forked from zbackup/zbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbackup_base.hh
88 lines (70 loc) · 2.95 KB
/
zbackup_base.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2012-2014 Konstantin Isakov <[email protected]> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
#ifndef ZBACKUP_BASE_HH_INCLUDED
#define ZBACKUP_BASE_HH_INCLUDED
#include <exception>
#include <string>
#include "ex.hh"
#include "chunk_index.hh"
#include "config.hh"
struct Paths
{
Config config;
std::string storageDir;
Paths( std::string const & storageDir );
Paths( std::string const & storageDir, Config const & );
std::string getTmpPath();
std::string getRestorePath();
std::string getCreatePath();
std::string getBundlesPath();
std::string getStorageInfoPath();
std::string getExtendedStorageInfoPath();
std::string getIndexPath();
std::string getBackupsPath();
};
class ZBackupBase: public Paths
{
public:
DEF_EX( Ex, "ZBackup exception", std::exception )
DEF_EX_STR( exWontOverwrite, "Won't overwrite existing file", Ex )
DEF_EX_STR( exInputError, "Error reading from input:", Ex )
DEF_EX( exWontReadFromTerminal, "Won't read data from a terminal", exInputError )
DEF_EX( exStdoutError, "Error writing to standard output", Ex )
DEF_EX( exWontWriteToTerminal, "Won't write data to a terminal", exStdoutError )
DEF_EX( exSerializeError, "Failed to serialize data", Ex )
DEF_EX( exParseError, "Failed to parse data", Ex )
DEF_EX( exChecksumError, "Checksum error", Ex )
DEF_EX_STR( exCantDeriveStorageDir, "The path must be within the backups/ dir:", Ex )
/// Opens the storage
ZBackupBase( std::string const & storageDir, std::string const & password );
ZBackupBase( std::string const & storageDir, std::string const & password, Config & configIn );
ZBackupBase( std::string const & storageDir, std::string const & password,
bool prohibitChunkIndexLoading );
ZBackupBase( std::string const & storageDir, std::string const & password, Config & configIn,
bool prohibitChunkIndexLoading );
/// Creates new storage
static void initStorage( std::string const & storageDir, std::string const & password,
bool isEncrypted, Config const & );
/// For a given file within the backups/ dir in the storage, returns its
/// storage dir or throws an exception
static std::string deriveStorageDirFromBackupsFile( std::string const & backupsFile, bool allowOutside = false );
void propagateUpdate();
void saveExtendedStorageInfo();
void setPassword( std::string const & password );
// returns true if data is changed
bool spawnEditor( std::string & data, bool( * validator )
( string const &, string const & ) );
// Edit current configuration
// returns true if configuration is changed
bool editConfigInteractively();
StorageInfo storageInfo;
EncryptionKey encryptionkey;
ExtendedStorageInfo extendedStorageInfo;
TmpMgr tmpMgr;
ChunkIndex chunkIndex;
Config config;
private:
StorageInfo loadStorageInfo();
ExtendedStorageInfo loadExtendedStorageInfo( EncryptionKey const & );
};
#endif