/** * {@inheritdoc} * * @throws file_updater_failure_exception When the file is not writable * @throws filesystem_exception When the filesystem class fails */ public function update_file($path_to_file_to_update, $source, $create_from_content = false) { $path_to_file_to_update = $this->phpbb_root_path . $path_to_file_to_update; $original_file_perms = false; // Maybe necessary for binary files $dir = dirname($path_to_file_to_update); if (!$this->filesystem->exists($dir)) { $this->make_dir($dir); } if (!$this->filesystem->is_writable($path_to_file_to_update)) { // Extract last 9 bits we actually need $original_file_perms = @fileperms($path_to_file_to_update) & 511; $this->filesystem->phpbb_chmod($path_to_file_to_update, filesystem::CHMOD_WRITE); } if (!$create_from_content) { try { $this->filesystem->copy($source, $path_to_file_to_update, true); } catch (filesystem_exception $e) { $this->write_file($path_to_file_to_update, $source, $create_from_content); } } else { $this->write_file($path_to_file_to_update, $source, $create_from_content); } if ($original_file_perms !== false) { $this->filesystem->phpbb_chmod($path_to_file_to_update, $original_file_perms); } }