/** * Restore Backup copy of a dataFile to where it belongs * * @since 3.4 * * @param string $file filepath of data file to restore from backup, locked to GSDATAPATH * @param bool $delete delete the backup * @return bool success */ function restore_datafile($filepath, $delete = true) { if (!filepath_is_safe($filepath, GSDATAPATH)) { return false; } $bakfilepath = getBackupFilePath($filepath); // backup original before restoring if (file_exists($filepath)) { rename_file($bakfilepath, $bakfilepath . '.tmp'); move_file($filepath, $bakfilepath); $bakfilepath .= '.tmp'; } if (!$delete) { return copy_file($bakfilepath, $filepath); } return move_file($bakfilepath, $filepath); }
/** * check if a file has a backup copy * * @since 3.4 * @param str $filepath filepath to data file * @return bool status */ function fileHasBackup($filepath) { $backupfilepath = getBackupFilePath($filepath); return file_exists($backupfilepath); }