CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
history.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_HISTORY_H_
6 #define CVMFS_HISTORY_H_
7 
8 #include <stdint.h>
9 #include <time.h>
10 
11 #include <string>
12 #include <vector>
13 
14 #include "crypto/hash.h"
15 
16 namespace history {
17 
33 class History {
34  public:
35  struct Branch {
37  Branch(const std::string &b, const std::string &p, uint64_t r)
38  : branch(b), parent(p), initial_revision(r) { }
39  std::string branch;
40  std::string parent;
41  uint64_t initial_revision;
42 
43  bool operator==(const Branch &other) const {
44  return (this->branch == other.branch) && (this->parent == other.parent)
45  && (this->initial_revision == other.initial_revision);
46  }
47 
48  // Used for sorting in unit tests
49  bool operator<(const Branch &other) const {
50  return (this->branch < other.branch);
51  }
52  };
53 
61  struct Tag {
62  Tag() : size(0), revision(0), timestamp(0) { }
63 
64  Tag(const std::string &n, const shash::Any &h, const uint64_t s,
65  const uint64_t r, const time_t t, const std::string &d,
66  const std::string &b)
67  : name(n)
68  , root_hash(h)
69  , size(s)
70  , revision(r)
71  , timestamp(t)
72  , description(d)
73  , branch(b) { }
74 
75  bool operator==(const Tag &other) const {
76  return (this->branch == other.branch)
77  && (this->revision == other.revision);
78  }
79 
80  bool operator<(const Tag &other) const {
81  if (this->timestamp == other.timestamp)
82  return this->revision < other.revision;
83  return this->timestamp < other.timestamp;
84  }
85 
86  bool operator>(const Tag &other) const {
87  if (this->timestamp == other.timestamp)
88  return this->revision > other.revision;
89  return this->timestamp > other.timestamp;
90  }
91 
92  std::string name;
94  uint64_t size;
95  uint64_t revision;
96  time_t timestamp;
97  std::string description;
101  std::string branch;
102  }; // struct Tag
103 
104 
105  public:
106  virtual ~History() { }
107 
108  virtual bool IsWritable() const = 0;
109  virtual unsigned GetNumberOfTags() const = 0;
110 
116  virtual bool BeginTransaction() const = 0;
117 
121  virtual bool CommitTransaction() const = 0;
122 
129  virtual bool SetPreviousRevision(const shash::Any &history_hash) = 0;
130  virtual shash::Any previous_revision() const = 0;
131 
132  virtual bool Insert(const Tag &tag) = 0;
133  virtual bool Remove(const std::string &name) = 0;
134  virtual bool Exists(const std::string &name) const = 0;
135  virtual bool GetByName(const std::string &name, Tag *tag) const = 0;
136  virtual bool GetByDate(const time_t timestamp, Tag *tag) const = 0;
137  virtual bool List(std::vector<Tag> *tags) const = 0;
138 
139  virtual bool GetBranchHead(const std::string &branch_name,
140  Tag *tag) const = 0;
141  virtual bool ExistsBranch(const std::string &branch_name) const = 0;
142  virtual bool InsertBranch(const Branch &branch) = 0;
147  virtual bool PruneBranches() = 0;
148  virtual bool ListBranches(std::vector<Branch> *branches) const = 0;
149 
154  virtual bool ListRecycleBin(std::vector<shash::Any> *hashes) const = 0;
155  virtual bool EmptyRecycleBin() = 0;
156 
167  virtual bool Rollback(const Tag &updated_target_tag) = 0;
168 
179  virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name,
180  std::vector<Tag> *tags) const = 0;
181 
188  virtual bool GetHashes(std::vector<shash::Any> *hashes) const = 0;
189 
190  // database file management controls
191  virtual void TakeDatabaseFileOwnership() = 0;
192  virtual void DropDatabaseFileOwnership() = 0;
193  virtual bool OwnsDatabaseFile() const = 0;
194 
195  virtual bool Vacuum() = 0;
196 
197  const std::string &fqrn() const { return fqrn_; }
198 
199  protected:
200  void set_fqrn(const std::string &fqrn) { fqrn_ = fqrn; }
201 
202  private:
203  std::string fqrn_;
204 };
205 
206 } // namespace history
207 
208 #endif // CVMFS_HISTORY_H_
bool operator<(const Branch &other) const
Definition: history.h:49
virtual bool PruneBranches()=0
std::string name
Definition: history.h:92
const history::History * history() const
virtual bool Exists(const std::string &name) const =0
virtual shash::Any previous_revision() const =0
virtual bool SetPreviousRevision(const shash::Any &history_hash)=0
virtual bool CommitTransaction() const =0
virtual unsigned GetNumberOfTags() const =0
bool operator==(const Tag &other) const
Definition: history.h:75
virtual ~History()
Definition: history.h:106
Tag(const std::string &n, const shash::Any &h, const uint64_t s, const uint64_t r, const time_t t, const std::string &d, const std::string &b)
Definition: history.h:64
const std::string & fqrn() const
Definition: history.h:197
virtual bool GetByDate(const time_t timestamp, Tag *tag) const =0
bool operator>(const Tag &other) const
Definition: history.h:86
std::string description
Definition: history.h:97
bool operator==(const Branch &other) const
Definition: history.h:43
virtual bool ListBranches(std::vector< Branch > *branches) const =0
virtual bool IsWritable() const =0
std::string parent
Definition: history.h:40
virtual bool List(std::vector< Tag > *tags) const =0
virtual bool InsertBranch(const Branch &branch)=0
virtual void DropDatabaseFileOwnership()=0
virtual bool ListRecycleBin(std::vector< shash::Any > *hashes) const =0
std::string fqrn_
Definition: history.h:203
virtual bool Vacuum()=0
virtual bool GetHashes(std::vector< shash::Any > *hashes) const =0
virtual bool Remove(const std::string &name)=0
virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name, std::vector< Tag > *tags) const =0
Branch(const std::string &b, const std::string &p, uint64_t r)
Definition: history.h:37
virtual bool ExistsBranch(const std::string &branch_name) const =0
virtual bool OwnsDatabaseFile() const =0
virtual bool Rollback(const Tag &updated_target_tag)=0
virtual bool GetByName(const std::string &name, Tag *tag) const =0
void set_fqrn(const std::string &fqrn)
Definition: history.h:200
virtual bool Insert(const Tag &tag)=0
virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const =0
shash::Any root_hash
Definition: history.h:93
virtual void TakeDatabaseFileOwnership()=0
uint64_t initial_revision
Definition: history.h:41
std::string branch
Definition: history.h:101
virtual bool EmptyRecycleBin()=0
bool operator<(const Tag &other) const
Definition: history.h:80
uint64_t revision
Definition: history.h:95
std::string branch
Definition: history.h:39
virtual bool BeginTransaction() const =0