// FileBackup.hpp // // Copyright (C) 2011 ARM Research Labs, LLC. // See www.armresearch.com for the copyright terms. // // This file defines the interface used by the FileBackup class. // #ifndef FileBackuphpp_included #define FileBackuphpp_included #include #include /// FileBackup class. // // This class provides capability to manage the backup and restore of // disk files. // ////////////////////////////////////////////////////////////////////////////////////////////////////////// class FileBackup { public: /// Create a backup of the specified file. // // This method first removes any .failed files, and then creates a // backup of the specified file. The name of the backup file is // the name of the file appended by the BackupSuffix data member. // // The file can be restored from the backup by RestoreFromBackup. // // \param[in] File is the file name to create a backup for. // // \throws std::runtime_error if an error is encountered. // // \see RestoreAllFilesFromBackup(). // void CreateBackupFile(std::string File); /// Remove the backups of all the specified files. // // This method removes the backup of the files specified by the // CreateBackup() method. // // \throws std::runtime_error if an error is encountered. // void RemoveAllBackupFiles(); /// Restore the all the specified files from the backup. // // This method restores the backup of the files specified by the // CreateBackupFile() method. // // The new file that is overwritten is first copied to the file // with a suffix ".failed". Then, if the original file existed, // it is restored. // // \throws std::runtime_error if an error is encountered. // // \see CreateBackupFile(). // void RestoreAllFilesFromBackup(); /// Get the name of the backup file. // // \param[in] File is the name of the file to back up. // // \returns the name of the backup file. // static std::string GetBackupFileName(std::string File); /// Get the name of the failed file. // // \param[in] File is the name of the file that contains the // configuration that failed (i.e. resulted in an error). // // \returns the name of the failed file. // static std::string GetFailedFileName(std::string File); /// Check if a file exists. // // \returns true if the file exists, false otherwise. // static bool FileExists(std::string File); private: /// Copy a file. // // \param[in] From is the name of the file to copy from. // // \param[in] To is the name of the file to copy to. // // \throws runtime_error in case of error. // void CopyFile(std::string From, std::string To); /// Suffix to append to the file name to obtain the backup file /// name. static const std::string BackupSuffix; /// Suffix to append to the file name to obtain the failed file /// name. static const std::string FailedSuffix; /// Typedef for container of names of files. // // The key is the name of the file to back up. The value is true // if the file to back up exists, false otherwise. typedef std::map FilenameContainer; /// Container of files that have backups. FilenameContainer OriginalFileExists; }; #endif