You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileBackup.hpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // FileBackup.hpp
  2. //
  3. // Copyright (C) 2011 ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // This file defines the interface used by the FileBackup class.
  7. //
  8. #ifndef FileBackuphpp_included
  9. #define FileBackuphpp_included
  10. #include <string>
  11. #include <vector>
  12. /// FileBackup class.
  13. //
  14. // This class provides capability to manage the backup and restore of
  15. // disk files.
  16. //
  17. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  18. class FileBackup {
  19. public:
  20. /// Constructor.
  21. //
  22. // \param[in] Suffix is the suffix to append to create the name of
  23. // the backup file.
  24. //
  25. FileBackup(std::string Suffix);
  26. /// Create a backup of the specified file.
  27. //
  28. // This method creates a backup of the specified file The name of
  29. // the link is the name of the file appended by the BackupSuffix
  30. // data member.
  31. //
  32. // The file can be restored from the backup by RestoreFromBackup.
  33. //
  34. // \param[in] File is the file name to create a backup for.
  35. //
  36. // \throws std::runtime_error in case of error.
  37. //
  38. // \see RestoreAllFilesFromBackup().
  39. //
  40. void CreateBackupFile(std::string File);
  41. /// Remove the backups of all the specified files.
  42. //
  43. // This method removes the backup of the files specified by the
  44. // CreateBackup() method.
  45. //
  46. // If an error is encountered, a message is output to std::cerr.
  47. //
  48. // \returns true if all backups were removed with no error, false otherwise.
  49. //
  50. bool RemoveAllBackupFiles();
  51. /// Restore the all the specified files from the backup.
  52. //
  53. // This method restores the backup of the files specified by the
  54. // CreateBackupFile() method.
  55. //
  56. // If an error is encountered, a message is output to std::cerr.
  57. //
  58. // \returns true if all files were restored with no error, false otherwise.
  59. //
  60. // \see CreateBackupFile().
  61. //
  62. bool RestoreAllFilesFromBackup();
  63. private:
  64. /// Get the name of the backup file.
  65. //
  66. // \param[in] File is the name of the file to back up.
  67. //
  68. // \returns the name of the backup file.
  69. //
  70. std::string GetBackupFileName(std::string File);
  71. /// Copy a file.
  72. //
  73. // \param[in] From is the name of the file to copy from.
  74. //
  75. // \param[in] To is the name of the file to copy to.
  76. //
  77. // \throws runtime_error in case of error.
  78. //
  79. void CopyFile(std::string From, std::string To);
  80. /// Suffix to append to the file name to obtain the backup file
  81. /// name.
  82. std::string BackupSuffix;
  83. /// Typedef for container of names of files.
  84. typedef std::vector<std::string> FilenameContainer;
  85. /// Container of files that have backups.
  86. FilenameContainer BackedUpFile;
  87. };
  88. #endif