Directory: | cvmfs/ |
---|---|
File: | cvmfs/sync_union.cc |
Date: | 2025-03-09 02:34:28 |
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 | 3 | SyncUnion::SyncUnion(AbstractSyncMediator *mediator, | |
15 | const std::string &rdonly_path, | ||
16 | const std::string &union_path, | ||
17 | 3 | const std::string &scratch_path) | |
18 | 3 | : rdonly_path_(rdonly_path), | |
19 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | scratch_path_(scratch_path), |
20 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | union_path_(union_path), |
21 | 3 | mediator_(mediator), | |
22 | 6 | initialized_(false) {} | |
23 | |||
24 | 3 | bool SyncUnion::Initialize() { | |
25 | 3 | mediator_->RegisterUnionEngine(this); | |
26 | 3 | initialized_ = true; | |
27 | 3 | 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 | 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 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, dir_name, kItemDir); | |
67 | ✗ | return ProcessDirectory(entry); | |
68 | } | ||
69 | |||
70 | ✗ | bool SyncUnion::ProcessDirectory(SharedPtr<SyncItem> entry) { | |
71 | ✗ | if (entry->IsNew()) { | |
72 | ✗ | mediator_->Add(entry); | |
73 | // Recursion stops here. All content of new directory | ||
74 | // is added later by the SyncMediator | ||
75 | ✗ | return false; | |
76 | } else { // directory already existed... | ||
77 | ✗ | if (entry->IsOpaqueDirectory()) { // was directory completely overwritten? | |
78 | ✗ | mediator_->Replace(entry); | |
79 | ✗ | return false; // <-- replace does not need any further recursion | |
80 | } else { // directory was just changed internally... only touch needed | ||
81 | ✗ | mediator_->Touch(entry); | |
82 | ✗ | return true; | |
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | // We don't have the directory that we are processing in the fs, we | ||
88 | // cannot recurse inside the directory. | ||
89 | // If the directory already exists, we simply remove it and we put it back the | ||
90 | // new one (some attributes may change) | ||
91 | // If it does not exists we simply add it. | ||
92 | 9 | bool SyncUnion::ProcessUnmaterializedDirectory(SharedPtr<SyncItem> entry) { | |
93 |
2/2✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
|
9 | if (entry->IsNew()) { |
94 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | mediator_->AddUnmaterializedDirectory(entry); |
95 | } | ||
96 | 9 | return true; | |
97 | } | ||
98 | |||
99 | ✗ | void SyncUnion::ProcessRegularFile(const string &parent_dir, | |
100 | const string &filename) { | ||
101 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessRegularFile(%s, %s)", | |
102 | parent_dir.c_str(), filename.c_str()); | ||
103 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, filename, kItemFile); | |
104 | ✗ | ProcessFile(entry); | |
105 | } | ||
106 | |||
107 | ✗ | void SyncUnion::ProcessSymlink(const string &parent_dir, | |
108 | const string &link_name) { | ||
109 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessSymlink(%s, %s)", | |
110 | parent_dir.c_str(), link_name.c_str()); | ||
111 | SharedPtr<SyncItem> entry = | ||
112 | ✗ | CreateSyncItem(parent_dir, link_name, kItemSymlink); | |
113 | ✗ | ProcessFile(entry); | |
114 | } | ||
115 | |||
116 | 10 | void SyncUnion::ProcessFile(SharedPtr<SyncItem> entry) { | |
117 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessFile(%s)", |
118 | 20 | entry->filename().c_str()); | |
119 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
|
10 | if (entry->IsWhiteout()) { |
120 | ✗ | mediator_->Remove(entry); | |
121 | } else { | ||
122 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | if (entry->IsNew()) { |
123 |
1/4✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
10 | LogCvmfs(kLogUnionFs, kLogVerboseMsg, "processing file [%s] as new (add)", |
124 | 20 | entry->filename().c_str()); | |
125 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | mediator_->Add(entry); |
126 | } else { | ||
127 | ✗ | LogCvmfs(kLogUnionFs, kLogVerboseMsg, | |
128 | "processing file [%s] as existing (touch)", | ||
129 | ✗ | entry->filename().c_str()); | |
130 | ✗ | mediator_->Touch(entry); | |
131 | } | ||
132 | } | ||
133 | 10 | } | |
134 | |||
135 | ✗ | void SyncUnion::EnterDirectory(const string &parent_dir, | |
136 | const string &dir_name) { | ||
137 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, dir_name, kItemDir); | |
138 | ✗ | mediator_->EnterDirectory(entry); | |
139 | } | ||
140 | |||
141 | ✗ | void SyncUnion::LeaveDirectory(const string &parent_dir, | |
142 | const string &dir_name) { | ||
143 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, dir_name, kItemDir); | |
144 | ✗ | mediator_->LeaveDirectory(entry); | |
145 | } | ||
146 | |||
147 | ✗ | void SyncUnion::ProcessCharacterDevice(const std::string &parent_dir, | |
148 | const std::string &filename) { | ||
149 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, | |
150 | "SyncUnionOverlayfs::ProcessCharacterDevice(%s, %s)", | ||
151 | parent_dir.c_str(), filename.c_str()); | ||
152 | SharedPtr<SyncItem> entry = | ||
153 | ✗ | CreateSyncItem(parent_dir, filename, kItemCharacterDevice); | |
154 | ✗ | ProcessFile(entry); | |
155 | } | ||
156 | |||
157 | ✗ | void SyncUnion::ProcessBlockDevice(const std::string &parent_dir, | |
158 | const std::string &filename) { | ||
159 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, | |
160 | "SyncUnionOverlayfs::ProcessBlockDevice(%s, %s)", parent_dir.c_str(), | ||
161 | filename.c_str()); | ||
162 | SharedPtr<SyncItem> entry = | ||
163 | ✗ | CreateSyncItem(parent_dir, filename, kItemBlockDevice); | |
164 | ✗ | ProcessFile(entry); | |
165 | } | ||
166 | |||
167 | ✗ | void SyncUnion::ProcessFifo(const std::string &parent_dir, | |
168 | const std::string &filename) { | ||
169 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnionOverlayfs::ProcessFifo(%s, %s)", | |
170 | parent_dir.c_str(), filename.c_str()); | ||
171 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, filename, kItemFifo); | |
172 | ✗ | ProcessFile(entry); | |
173 | } | ||
174 | |||
175 | ✗ | void SyncUnion::ProcessSocket(const std::string &parent_dir, | |
176 | const std::string &filename) { | ||
177 | ✗ | LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnionOverlayfs::ProcessSocket(%s, %s)", | |
178 | parent_dir.c_str(), filename.c_str()); | ||
179 | ✗ | SharedPtr<SyncItem> entry = CreateSyncItem(parent_dir, filename, kItemSocket); | |
180 | ✗ | ProcessFile(entry); | |
181 | } | ||
182 | |||
183 | } // namespace publish | ||
184 |