CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_counters.cc
Go to the documentation of this file.
1 
5 #include "catalog_counters.h"
6 
7 #include "directory_entry.h"
8 #include "util/exception.h"
9 
10 namespace catalog {
11 
12 void DeltaCounters::ApplyDelta(const DirectoryEntry &dirent, const int delta) {
13  if (dirent.IsRegular()) {
14  self.regular_files += delta;
15  self.file_size += delta * dirent.size();
16  if (dirent.IsChunkedFile()) {
17  self.chunked_files += delta;
18  self.chunked_file_size += delta * dirent.size();
19  }
20  if (dirent.IsExternalFile()) {
21  self.externals += delta;
22  self.external_file_size += delta * dirent.size();
23  }
24  } else if (dirent.IsLink()) {
25  self.symlinks += delta;
26  } else if (dirent.IsSpecial()) {
27  self.specials += delta;
28  } else if (dirent.IsDirectory()) {
29  self.directories += delta;
30  } else {
31  PANIC(NULL);
32  }
33  if (dirent.HasXattrs()) {
34  self.xattrs += delta;
35  }
36 }
37 
38 
40  parent->subtree.Add(self);
41  parent->subtree.Add(subtree);
42 }
43 
45  subtree.Subtract(child.self);
46  subtree.Subtract(child.subtree);
47 }
48 
49 
50 void Counters::ApplyDelta(const DeltaCounters &delta) {
51  self.Add(delta.self);
52  subtree.Add(delta.subtree);
53 }
54 
55 
57  delta->subtree.Add(self);
58  delta->subtree.Add(subtree);
59 }
60 
61 void Counters::MergeIntoParent(DeltaCounters *parent_delta) const {
62  parent_delta->self.Add(self);
63  parent_delta->subtree.Subtract(self);
64 }
65 
66 
68  return self.regular_files + self.symlinks + self.specials + self.directories;
69 }
70 
71 
73  return subtree.regular_files + subtree.symlinks + subtree.specials +
74  subtree.directories;
75 }
76 
77 
79  return GetSelfEntries() + GetSubtreeEntries();
80 }
81 
82 
83 DeltaCounters Counters::Diff(const Counters &from, const Counters &to) {
84  DeltaCounters result;
85  result.self.Add(to.self);
86  result.subtree.Add(to.subtree);
87  result.self.Subtract(from.self);
88  result.subtree.Subtract(from.subtree);
89  return result;
90 }
91 
92 } // namespace catalog
bool IsExternalFile() const
bool IsSpecial() const
bool IsDirectory() const
bool IsChunkedFile() const
#define PANIC(...)
Definition: exception.h:29
uint64_t size() const
void ApplyDelta(const DeltaCounters &delta)
static DeltaCounters Diff(const Counters &from, const Counters &to)
Counters_t GetSelfEntries() const
void AddAsSubtree(DeltaCounters *delta) const
bool IsLink() const
bool HasXattrs() const
bool IsRegular() const
uint64_t Counters_t
void PopulateToParent(DeltaCounters *parent) const
Counters_t GetSubtreeEntries() const
void ApplyDelta(const DirectoryEntry &dirent, const int delta)
Counters_t GetAllEntries() const
void MergeIntoParent(DeltaCounters *parent_delta) const
void RemoveFromSubtree(const DeltaCounters &child)