| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/catalog_counters.cc |
| Date: | 2025-11-09 02:35:23 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 48 | 53 | 90.6% |
| Branches: | 12 | 14 | 85.7% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * This file is part of the CernVM File System. | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include "catalog_counters.h" | ||
| 6 | |||
| 7 | #include "directory_entry.h" | ||
| 8 | #include "util/exception.h" | ||
| 9 | |||
| 10 | namespace catalog { | ||
| 11 | |||
| 12 | 23118 | void DeltaCounters::ApplyDelta(const DirectoryEntry &dirent, const int delta) { | |
| 13 |
2/2✓ Branch 1 taken 15091 times.
✓ Branch 2 taken 8027 times.
|
23118 | if (dirent.IsRegular()) { |
| 14 | 15091 | self.regular_files += delta; | |
| 15 | 15091 | self.file_size += delta * dirent.size(); | |
| 16 |
2/2✓ Branch 1 taken 574 times.
✓ Branch 2 taken 14517 times.
|
15091 | if (dirent.IsChunkedFile()) { |
| 17 | 574 | self.chunked_files += delta; | |
| 18 | 574 | self.chunked_file_size += delta * dirent.size(); | |
| 19 | } | ||
| 20 |
2/2✓ Branch 1 taken 147 times.
✓ Branch 2 taken 14944 times.
|
15091 | if (dirent.IsExternalFile()) { |
| 21 | 147 | self.externals += delta; | |
| 22 | 147 | self.external_file_size += delta * dirent.size(); | |
| 23 | } | ||
| 24 |
2/2✓ Branch 1 taken 580 times.
✓ Branch 2 taken 7447 times.
|
8027 | } else if (dirent.IsLink()) { |
| 25 | 580 | self.symlinks += delta; | |
| 26 |
2/2✓ Branch 1 taken 196 times.
✓ Branch 2 taken 7251 times.
|
7447 | } else if (dirent.IsSpecial()) { |
| 27 | 196 | self.specials += delta; | |
| 28 |
1/2✓ Branch 1 taken 7251 times.
✗ Branch 2 not taken.
|
7251 | } else if (dirent.IsDirectory()) { |
| 29 | 7251 | self.directories += delta; | |
| 30 | } else { | ||
| 31 | ✗ | PANIC(NULL); | |
| 32 | } | ||
| 33 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23118 times.
|
23118 | if (dirent.HasXattrs()) { |
| 34 | ✗ | self.xattrs += delta; | |
| 35 | } | ||
| 36 | 23118 | } | |
| 37 | |||
| 38 | |||
| 39 | 1607 | void DeltaCounters::PopulateToParent(DeltaCounters *parent) const { | |
| 40 | 1607 | parent->subtree.Add(self); | |
| 41 | 1607 | parent->subtree.Add(subtree); | |
| 42 | 1607 | } | |
| 43 | |||
| 44 | ✗ | void DeltaCounters::RemoveFromSubtree(const DeltaCounters &child) { | |
| 45 | ✗ | subtree.Subtract(child.self); | |
| 46 | ✗ | subtree.Subtract(child.subtree); | |
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | 166 | void Counters::ApplyDelta(const DeltaCounters &delta) { | |
| 51 | 166 | self.Add(delta.self); | |
| 52 | 166 | subtree.Add(delta.subtree); | |
| 53 | 166 | } | |
| 54 | |||
| 55 | |||
| 56 | 49 | void Counters::AddAsSubtree(DeltaCounters *delta) const { | |
| 57 | 49 | delta->subtree.Add(self); | |
| 58 | 49 | delta->subtree.Add(subtree); | |
| 59 | 49 | } | |
| 60 | |||
| 61 | 166 | void Counters::MergeIntoParent(DeltaCounters *parent_delta) const { | |
| 62 | 166 | parent_delta->self.Add(self); | |
| 63 | 166 | parent_delta->subtree.Subtract(self); | |
| 64 | 166 | } | |
| 65 | |||
| 66 | |||
| 67 | 1136 | Counters_t Counters::GetSelfEntries() const { | |
| 68 | 1136 | return self.regular_files + self.symlinks + self.specials + self.directories; | |
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | 630 | Counters_t Counters::GetSubtreeEntries() const { | |
| 73 | 630 | return subtree.regular_files + subtree.symlinks + subtree.specials | |
| 74 | 630 | + subtree.directories; | |
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | 532 | Counters_t Counters::GetAllEntries() const { | |
| 79 | 532 | return GetSelfEntries() + GetSubtreeEntries(); | |
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | 343 | DeltaCounters Counters::Diff(const Counters &from, const Counters &to) { | |
| 84 | 343 | DeltaCounters result; | |
| 85 | 343 | result.self.Add(to.self); | |
| 86 | 343 | result.subtree.Add(to.subtree); | |
| 87 | 343 | result.self.Subtract(from.self); | |
| 88 | 343 | result.subtree.Subtract(from.subtree); | |
| 89 | 343 | return result; | |
| 90 | } | ||
| 91 | |||
| 92 | } // namespace catalog | ||
| 93 |