File: index_file.hh

package info (click to toggle)
zbackup 1.3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 500 kB
  • ctags: 568
  • sloc: cpp: 4,032; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,611 bytes parent folder | download
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
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org>
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE

#ifndef INDEX_FILE_HH_INCLUDED__
#define INDEX_FILE_HH_INCLUDED__

#include <exception>
#include <string>

#include "adler32.hh"
#include "bundle.hh"
#include "encrypted_file.hh"
#include "encryption_key.hh"
#include "ex.hh"
#include "file.hh"
#include "nocopy.hh"
#include "zbackup.pb.h"

/// Index files store all existing chunk ids and their bundle ids. This
/// information can also be retrieved by scanning all bundle files, but that
/// would incur a lot of disk seeks which we want to minimize here
namespace IndexFile {

using std::string;

/// Creates index files
class Writer: NoCopy
{
  EncryptedFile::OutputStream stream;

public:
  /// Creates a new chunk log. Initially it is stored in a temporary file
  Writer( EncryptionKey const &, string const & fileName );

  /// Adds a bundle info to the log
  void add( BundleInfo const &, Bundle::Id const & bundleId );

  /// Finalizes the file
  ~Writer();
};

/// Reads index files
class Reader: NoCopy
{
  EncryptedFile::InputStream stream;

public:
  DEF_EX( Ex, "Index file reader exception", std::exception )
  DEF_EX( exUnsupportedVersion, "Unsupported version of the index file format", Ex )
  DEF_EX( exIncorrectBundleIdSize, "Incorrect bundle id size encountered", Ex )

  Reader( EncryptionKey const &, string const & fileName );

  /// Reads the next record from the file. Returns false if no more records can
  /// be found
  bool readNextRecord( BundleInfo &, Bundle::Id & bundleId );
};
}

#endif