1 // Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS 2 // Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE 3 4 #ifndef ZBACKUP_BASE_HH_INCLUDED__ 5 #define ZBACKUP_BASE_HH_INCLUDED__ 6 7 #include <exception> 8 #include <string> 9 10 #include "ex.hh" 11 #include "chunk_index.hh" 12 13 struct Paths 14 { 15 std::string storageDir; 16 17 Paths( std::string const & storageDir ); 18 19 std::string getTmpPath(); 20 std::string getRestorePath(); 21 std::string getCreatePath(); 22 std::string getBundlesPath(); 23 std::string getStorageInfoPath(); 24 std::string getIndexPath(); 25 std::string getBackupsPath(); 26 }; 27 28 class ZBackupBase: public Paths 29 { 30 public: 31 DEF_EX( Ex, "ZBackup exception", std::exception ) 32 DEF_EX_STR( exWontOverwrite, "Won't overwrite existing file", Ex ) 33 DEF_EX( exStdinError, "Error reading from standard input", Ex ) 34 DEF_EX( exWontReadFromTerminal, "Won't read data from a terminal", exStdinError ) 35 DEF_EX( exStdoutError, "Error writing to standard output", Ex ) 36 DEF_EX( exWontWriteToTerminal, "Won't write data to a terminal", exStdoutError ) 37 DEF_EX( exSerializeError, "Failed to serialize data", Ex ) 38 DEF_EX( exParseError, "Failed to parse data", Ex ) 39 DEF_EX( exChecksumError, "Checksum error", Ex ) 40 DEF_EX_STR( exCantDeriveStorageDir, "The path must be within the backups/ dir:", Ex ) 41 42 /// Opens the storage 43 ZBackupBase( std::string const & storageDir, std::string const & password ); 44 ZBackupBase( std::string const & storageDir, std::string const & password, bool prohibitChunkIndexLoading ); 45 46 /// Creates new storage 47 static void initStorage( std::string const & storageDir, std::string const & password, 48 bool isEncrypted ); 49 50 /// For a given file within the backups/ dir in the storage, returns its 51 /// storage dir or throws an exception 52 static std::string deriveStorageDirFromBackupsFile( std::string const & backupsFile, bool allowOutside = false ); 53 54 void useDefaultCompressionMethod(); 55 56 StorageInfo storageInfo; 57 EncryptionKey encryptionkey; 58 TmpMgr tmpMgr; 59 ChunkIndex chunkIndex; 60 61 private: 62 StorageInfo loadStorageInfo(); 63 }; 64 65 66 #endif 67