public function saveResetToken($id, $data)
    {
        $fileName = $this->dir . self::RESET_TOKENS;
        $tokens = array();
        $writer = new FileWriter($fileName);

        // Get exclusive access and read the current tokens
        try {
            $writer->open();
            $reader = new \PicoAuth\Storage\File\FileReader(
                $fileName,
                ["handle"=>$writer->getHandle()]
            );
            $yaml = $reader->read();
            $tokens = \Symfony\Component\Yaml\Yaml::parse($yaml);
        } catch (\RuntimeException $e) {
            // File doesn't exist, no write permission, read or parse error
            // If not writeable, will fail in saveResetTokens
            $tokens = array();
        }

        // Add the new token entry
        $tokens[$id] = $data;

        // Save the token file, while keeping the same file lock
        $this->saveResetTokens($tokens, $writer);
    }
public function saveResetToken($id, $data)
    {
        $fileName = $this->dir . self::RESET_TOKENS;
        $tokens = array();
        $writer = new FileWriter($fileName);

        // Get exclusive access and read the current tokens
        try {
            $writer->open();
            $reader = new \PicoAuth\Storage\File\FileReader(
                $fileName,
                ["handle"=>$writer->getHandle()]
            );
            $yaml = $reader->read();
            $tokens = \Symfony\Component\Yaml\Yaml::parse($yaml);
        } catch (\RuntimeException $e) {
            // File doesn't exist, no write permission, read or parse error
            // If not writeable, will fail in saveResetTokens
            $tokens = array();
        }

        // Add the new token entry
        $tokens[$id] = $data;

        // Save the token file, while keeping the same file lock
        $this->saveResetTokens($tokens, $writer);
    }
{@inheritdoc}

When adding a new token entry, the file must be read first, the token
added and then saved. An exclusive access to the token file must be held
since the initial read in order to avoid lost writes.