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