src/Storage/File/FileWriter.php
protected function createBkFile()
    {
        if (!is_writable(dirname($this->filePath))) {
            return;
        }
        
        $this->bkFilePath = $this->filePath . '.' . date("y-m-d-H-i-s") . '.bak';
        $bkHandle = @fopen($this->bkFilePath, 'x+');
        if ($bkHandle === false) {
            $this->close();
            throw new \RuntimeException("Could not create a temporary file " . $this->bkFilePath);
        }
        $stat = fstat($this->handle);
        if (stream_copy_to_stream($this->handle, $bkHandle) !== $stat['size']) {
            $this->close();
            throw new \RuntimeException("Could not create a copy of " . $this->filePath);
        }
        
        if (!fclose($bkHandle)) {
            throw new \RuntimeException("Could not close a backup file " . $this->bkFilePath);
        }
        
        fseek($this->handle, 0);
    }
protected function createBkFile()
    {
        if (!is_writable(dirname($this->filePath))) {
            return;
        }
        
        $this->bkFilePath = $this->filePath . '.' . date("y-m-d-H-i-s") . '.bak';
        $bkHandle = @fopen($this->bkFilePath, 'x+');
        if ($bkHandle === false) {
            $this->close();
            throw new \RuntimeException("Could not create a temporary file " . $this->bkFilePath);
        }
        $stat = fstat($this->handle);
        if (stream_copy_to_stream($this->handle, $bkHandle) !== $stat['size']) {
            $this->close();
            throw new \RuntimeException("Could not create a copy of " . $this->filePath);
        }
        
        if (!fclose($bkHandle)) {
            throw new \RuntimeException("Could not close a backup file " . $this->bkFilePath);
        }
        
        fseek($this->handle, 0);
    }
Creates a backup file before writing

If there is no write permission for the directory the original file is in,
the backup file is not created. That way this option can be disabled,
if not considered as needed.

@throws \RuntimeException On write error