GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/sync_union.cc
Date: 2025-06-22 02:36:02
Exec Total Coverage
Lines: 24 87 27.6%
Branches: 10 133 7.5%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System
3 */
4
5 #define __STDC_FORMAT_MACROS
6
7 #include "sync_union.h"
8
9 #include "sync_mediator.h"
10 #include "util/shared_ptr.h"
11
12 namespace publish {
13
14 42 SyncUnion::SyncUnion(AbstractSyncMediator *mediator,
15 const std::string &rdonly_path,
16 const std::string &union_path,
17 42 const std::string &scratch_path)
18 42 : rdonly_path_(rdonly_path)
19
1/2
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
42 , scratch_path_(scratch_path)
20
1/2
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
42 , union_path_(union_path)
21 42 , mediator_(mediator)
22 84 , initialized_(false) { }
23
24 42 bool SyncUnion::Initialize() {
25 42 mediator_->RegisterUnionEngine(this);
26 42 initialized_ = true;
27 42 return true;
28 }
29
30 SharedPtr<SyncItem> SyncUnion::CreateSyncItem(
31 const std::string &relative_parent_path, const std::string &filename,
32 const SyncItemType entry_type) const {
33 const SharedPtr<SyncItem> entry = SharedPtr<SyncItem>(
34 new SyncItemNative(relative_parent_path, filename, this, entry_type));
35
36 PreprocessSyncItem(entry);
37 if (entry_type == kItemFile) {
38 entry->SetExternalData(mediator_->IsExternalData());
39 entry->SetDirectIo(mediator_->IsDirectIo());
40 if (!(entry->IsValidGraft() && entry->HasCompressionAlgorithm())) {
41 entry->SetCompressionAlgorithm(mediator_->GetCompressionAlgorithm());
42 }
43 }
44 return entry;
45 }
46
47 void SyncUnion::PreprocessSyncItem(SharedPtr<SyncItem> entry) const {
48 if (IsWhiteoutEntry(entry)) {
49 entry->MarkAsWhiteout(UnwindWhiteoutFilename(entry));
50 }
51
52 if (entry->IsDirectory() && IsOpaqueDirectory(entry)) {
53 entry->MarkAsOpaqueDirectory();
54 }
55 }
56
57 bool SyncUnion::IgnoreFilePredicate(const std::string &parent_dir,
58 const std::string &filename) {
59 return false;
60 }
61
62 bool SyncUnion::ProcessDirectory(const string &parent_dir,
63 const string &dir_name) {
64 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessDirectory(%s, %s)",
65 parent_dir.c_str(), dir_name.c_str());
66 const SharedPtr<SyncItem> entry =
67 CreateSyncItem(parent_dir, dir_name, kItemDir);
68 return ProcessDirectory(entry);
69 }
70
71 bool SyncUnion::ProcessDirectory(SharedPtr<SyncItem> entry) {
72 if (entry->IsNew()) {
73 mediator_->Add(entry);
74 // Recursion stops here. All content of new directory
75 // is added later by the SyncMediator
76 return false;
77 } else { // directory already existed...
78 if (entry->IsOpaqueDirectory()) { // was directory completely overwritten?
79 mediator_->Replace(entry);
80 return false; // <-- replace does not need any further recursion
81 } else { // directory was just changed internally... only touch needed
82 mediator_->Touch(entry);
83 return true;
84 }
85 }
86 }
87
88 // We don't have the directory that we are processing in the fs, we
89 // cannot recurse inside the directory.
90 // If the directory already exists, we simply remove it and we put it back the
91 // new one (some attributes may change)
92 // If it does not exists we simply add it.
93 126 bool SyncUnion::ProcessUnmaterializedDirectory(SharedPtr<SyncItem> entry) {
94
2/2
✓ Branch 2 taken 98 times.
✓ Branch 3 taken 28 times.
126 if (entry->IsNew()) {
95
1/2
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
98 mediator_->AddUnmaterializedDirectory(entry);
96 }
97 126 return true;
98 }
99
100 void SyncUnion::ProcessRegularFile(const string &parent_dir,
101 const string &filename) {
102 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessRegularFile(%s, %s)",
103 parent_dir.c_str(), filename.c_str());
104 const SharedPtr<SyncItem> entry =
105 CreateSyncItem(parent_dir, filename, kItemFile);
106 ProcessFile(entry);
107 }
108
109 void SyncUnion::ProcessSymlink(const string &parent_dir,
110 const string &link_name) {
111 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessSymlink(%s, %s)",
112 parent_dir.c_str(), link_name.c_str());
113 const SharedPtr<SyncItem> entry =
114 CreateSyncItem(parent_dir, link_name, kItemSymlink);
115 ProcessFile(entry);
116 }
117
118 140 void SyncUnion::ProcessFile(SharedPtr<SyncItem> entry) {
119
1/2
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
140 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessFile(%s)",
120 280 entry->filename().c_str());
121
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 140 times.
140 if (entry->IsWhiteout()) {
122 mediator_->Remove(entry);
123 } else {
124
1/2
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
140 if (entry->IsNew()) {
125
1/4
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
140 LogCvmfs(kLogUnionFs, kLogVerboseMsg, "processing file [%s] as new (add)",
126 280 entry->filename().c_str());
127
1/2
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
140 mediator_->Add(entry);
128 } else {
129 LogCvmfs(kLogUnionFs, kLogVerboseMsg,
130 "processing file [%s] as existing (touch)",
131 entry->filename().c_str());
132 mediator_->Touch(entry);
133 }
134 }
135 140 }
136
137 void SyncUnion::EnterDirectory(const string &parent_dir,
138 const string &dir_name) {
139 const SharedPtr<SyncItem> entry =
140 CreateSyncItem(parent_dir, dir_name, kItemDir);
141 mediator_->EnterDirectory(entry);
142 }
143
144 void SyncUnion::LeaveDirectory(const string &parent_dir,
145 const string &dir_name) {
146 const SharedPtr<SyncItem> entry =
147 CreateSyncItem(parent_dir, dir_name, kItemDir);
148 mediator_->LeaveDirectory(entry);
149 }
150
151 void SyncUnion::ProcessCharacterDevice(const std::string &parent_dir,
152 const std::string &filename) {
153 LogCvmfs(kLogUnionFs, kLogDebug,
154 "SyncUnionOverlayfs::ProcessCharacterDevice(%s, %s)",
155 parent_dir.c_str(), filename.c_str());
156 const SharedPtr<SyncItem> entry =
157 CreateSyncItem(parent_dir, filename, kItemCharacterDevice);
158 ProcessFile(entry);
159 }
160
161 void SyncUnion::ProcessBlockDevice(const std::string &parent_dir,
162 const std::string &filename) {
163 LogCvmfs(kLogUnionFs, kLogDebug,
164 "SyncUnionOverlayfs::ProcessBlockDevice(%s, %s)", parent_dir.c_str(),
165 filename.c_str());
166 const SharedPtr<SyncItem> entry =
167 CreateSyncItem(parent_dir, filename, kItemBlockDevice);
168 ProcessFile(entry);
169 }
170
171 void SyncUnion::ProcessFifo(const std::string &parent_dir,
172 const std::string &filename) {
173 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnionOverlayfs::ProcessFifo(%s, %s)",
174 parent_dir.c_str(), filename.c_str());
175 const SharedPtr<SyncItem> entry =
176 CreateSyncItem(parent_dir, filename, kItemFifo);
177 ProcessFile(entry);
178 }
179
180 void SyncUnion::ProcessSocket(const std::string &parent_dir,
181 const std::string &filename) {
182 LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnionOverlayfs::ProcessSocket(%s, %s)",
183 parent_dir.c_str(), filename.c_str());
184 const SharedPtr<SyncItem> entry =
185 CreateSyncItem(parent_dir, filename, kItemSocket);
186 ProcessFile(entry);
187 }
188
189 } // namespace publish
190