CernVM-FS  2.10.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 "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, unsigned r)
38  : branch(b), parent(p), initial_revision(r) { }
39  std::string branch;
40  std::string parent;
41  unsigned initial_revision;
42 
43  bool operator ==(const Branch &other) const {
44  return (this->branch == other.branch) &&
45  (this->parent == other.parent) &&
46  (this->initial_revision == other.initial_revision);
47  }
48 
49  // Used for sorting in unit tests
50  bool operator <(const Branch &other) const {
51  return (this->branch < other.branch);
52  }
53  };
54 
62  struct Tag {
63  Tag() :
64  size(0), revision(0), timestamp(0) {}
65 
66  Tag(const std::string &n, const shash::Any &h, const uint64_t s,
67  const unsigned r, const time_t t, const std::string &d,
68  const std::string &b) :
69  name(n), root_hash(h), size(s), revision(r), timestamp(t),
70  description(d), branch(b) {}
71 
72  bool operator ==(const Tag &other) const {
73  return (this->branch == other.branch) &&
74  (this->revision == other.revision);
75  }
76 
77  bool operator <(const Tag &other) const {
78  if (this->timestamp == other.timestamp)
79  return this->revision < other.revision;
80  return this->timestamp < other.timestamp;
81  }
82 
83  bool operator >(const Tag &other) const {
84  if (this->timestamp == other.timestamp)
85  return this->revision > other.revision;
86  return this->timestamp > other.timestamp;
87  }
88 
89  std::string name;
91  uint64_t size;
92  unsigned revision;
93  time_t timestamp;
94  std::string description;
98  std::string branch;
99  }; // struct Tag
100 
101 
102  public:
103  virtual ~History() { }
104 
105  virtual bool IsWritable() const = 0;
106  virtual unsigned GetNumberOfTags() const = 0;
107 
113  virtual bool BeginTransaction() const = 0;
114 
118  virtual bool CommitTransaction() const = 0;
119 
126  virtual bool SetPreviousRevision(const shash::Any &history_hash) = 0;
127  virtual shash::Any previous_revision() const = 0;
128 
129  virtual bool Insert(const Tag &tag) = 0;
130  virtual bool Remove(const std::string &name) = 0;
131  virtual bool Exists(const std::string &name) const = 0;
132  virtual bool GetByName(const std::string &name, Tag *tag) const = 0;
133  virtual bool GetByDate(const time_t timestamp, Tag *tag) const = 0;
134  virtual bool List(std::vector<Tag> *tags) const = 0;
135 
136  virtual bool GetBranchHead(const std::string &branch_name, Tag *tag)
137  const = 0;
138  virtual bool ExistsBranch(const std::string &branch_name) const = 0;
139  virtual bool InsertBranch(const Branch &branch) = 0;
144  virtual bool PruneBranches() = 0;
145  virtual bool ListBranches(std::vector<Branch> *branches) const = 0;
146 
151  virtual bool ListRecycleBin(std::vector<shash::Any> *hashes) const = 0;
152  virtual bool EmptyRecycleBin() = 0;
153 
164  virtual bool Rollback(const Tag &updated_target_tag) = 0;
165 
176  virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name,
177  std::vector<Tag> *tags) const = 0;
178 
185  virtual bool GetHashes(std::vector<shash::Any> *hashes) const = 0;
186 
187  // database file management controls
188  virtual void TakeDatabaseFileOwnership() = 0;
189  virtual void DropDatabaseFileOwnership() = 0;
190  virtual bool OwnsDatabaseFile() const = 0;
191 
192  virtual bool Vacuum() = 0;
193 
194  const std::string& fqrn() const { return fqrn_; }
195 
196  protected:
197  void set_fqrn(const std::string &fqrn) { fqrn_ = fqrn; }
198 
199  private:
200  std::string fqrn_;
201 };
202 
203 } // namespace history
204 
205 #endif // CVMFS_HISTORY_H_
unsigned initial_revision
Definition: history.h:41
bool operator<(const Branch &other) const
Definition: history.h:50
virtual bool PruneBranches()=0
std::string name
Definition: history.h:89
const history::History * history() const
unsigned revision
Definition: history.h:92
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
Branch(const std::string &b, const std::string &p, unsigned r)
Definition: history.h:37
bool operator==(const Tag &other) const
Definition: history.h:72
virtual ~History()
Definition: history.h:103
const std::string & fqrn() const
Definition: history.h:194
virtual bool GetByDate(const time_t timestamp, Tag *tag) const =0
bool operator>(const Tag &other) const
Definition: history.h:83
std::string description
Definition: history.h:94
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:200
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
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:197
virtual bool Insert(const Tag &tag)=0
virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const =0
Tag(const std::string &n, const shash::Any &h, const uint64_t s, const unsigned r, const time_t t, const std::string &d, const std::string &b)
Definition: history.h:66
shash::Any root_hash
Definition: history.h:90
virtual void TakeDatabaseFileOwnership()=0
std::string branch
Definition: history.h:98
virtual bool EmptyRecycleBin()=0
bool operator<(const Tag &other) const
Definition: history.h:77
std::string branch
Definition: history.h:39
virtual bool BeginTransaction() const =0