Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <map>
  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. /// Create a backup of the specified file.
  21. //
  22. // This method first removes any .failed files, and then creates a
  23. // backup of the specified file. The name of the backup file is
  24. // the name of the file appended by the BackupSuffix data member.
  25. //
  26. // The file can be restored from the backup by RestoreFromBackup.
  27. //
  28. // \param[in] File is the file name to create a backup for.
  29. //
  30. // \throws std::runtime_error if an error is encountered.
  31. //
  32. // \see RestoreAllFilesFromBackup().
  33. //
  34. void CreateBackupFile(std::string File);
  35. /// Remove the backups of all the specified files.
  36. //
  37. // This method removes the backup of the files specified by the
  38. // CreateBackup() method.
  39. //
  40. // \throws std::runtime_error if an error is encountered.
  41. //
  42. void RemoveAllBackupFiles();
  43. /// Restore the all the specified files from the backup.
  44. //
  45. // This method restores the backup of the files specified by the
  46. // CreateBackupFile() method.
  47. //
  48. // The new file that is overwritten is first copied to the file
  49. // with a suffix ".failed". Then, if the original file existed,
  50. // it is restored.
  51. //
  52. // \throws std::runtime_error if an error is encountered.
  53. //
  54. // \see CreateBackupFile().
  55. //
  56. void RestoreAllFilesFromBackup();
  57. /// Get the name of the backup file.
  58. //
  59. // \param[in] File is the name of the file to back up.
  60. //
  61. // \returns the name of the backup file.
  62. //
  63. static std::string GetBackupFileName(std::string File);
  64. /// Get the name of the failed file.
  65. //
  66. // \param[in] File is the name of the file that contains the
  67. // configuration that failed (i.e. resulted in an error).
  68. //
  69. // \returns the name of the failed file.
  70. //
  71. static std::string GetFailedFileName(std::string File);
  72. /// Check if a file exists.
  73. //
  74. // \returns true if the file exists, false otherwise.
  75. //
  76. static bool FileExists(std::string File);
  77. private:
  78. /// Copy a file.
  79. //
  80. // \param[in] From is the name of the file to copy from.
  81. //
  82. // \param[in] To is the name of the file to copy to.
  83. //
  84. // \throws runtime_error in case of error.
  85. //
  86. void CopyFile(std::string From, std::string To);
  87. /// Suffix to append to the file name to obtain the backup file
  88. /// name.
  89. static const std::string BackupSuffix;
  90. /// Suffix to append to the file name to obtain the failed file
  91. /// name.
  92. static const std::string FailedSuffix;
  93. /// Typedef for container of names of files.
  94. //
  95. // The key is the name of the file to back up. The value is true
  96. // if the file to back up exists, false otherwise.
  97. typedef std::map<std::string, bool> FilenameContainer;
  98. /// Container of files that have backups.
  99. FilenameContainer OriginalFileExists;
  100. };
  101. #endif