File: zbackup_base.hh

package info (click to toggle)
zbackup 1.5-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 868 kB
  • sloc: cpp: 6,957; ansic: 468; python: 207; makefile: 10
file content (88 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download | duplicates (2)
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 <ikm@zbackup.org> 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