CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sync_union.cc
Go to the documentation of this file.
1 
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 
15  const std::string &rdonly_path,
16  const std::string &union_path,
17  const std::string &scratch_path)
18  : rdonly_path_(rdonly_path),
19  scratch_path_(scratch_path),
20  union_path_(union_path),
21  mediator_(mediator),
22  initialized_(false) {}
23 
26  initialized_ = true;
27  return true;
28 }
29 
31  const std::string &relative_parent_path, const std::string &filename,
32  const SyncItemType entry_type) const {
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 
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 
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.
93  if (entry->IsNew()) {
95  }
96  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 
117  LogCvmfs(kLogUnionFs, kLogDebug, "SyncUnion::ProcessFile(%s)",
118  entry->filename().c_str());
119  if (entry->IsWhiteout()) {
120  mediator_->Remove(entry);
121  } else {
122  if (entry->IsNew()) {
123  LogCvmfs(kLogUnionFs, kLogVerboseMsg, "processing file [%s] as new (add)",
124  entry->filename().c_str());
125  mediator_->Add(entry);
126  } else {
128  "processing file [%s] as existing (touch)",
129  entry->filename().c_str());
130  mediator_->Touch(entry);
131  }
132  }
133 }
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) {
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) {
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
virtual void LeaveDirectory(const std::string &parent_dir, const std::string &dir_name)
Definition: sync_union.cc:141
#define LogCvmfs(source, mask,...)
Definition: logging.h:20
virtual bool ProcessUnmaterializedDirectory(SharedPtr< SyncItem > entry)
Definition: sync_union.cc:92
virtual void LeaveDirectory(SharedPtr< SyncItem > entry)=0
virtual void AddUnmaterializedDirectory(SharedPtr< SyncItem > entry)=0
virtual void Replace(SharedPtr< SyncItem > entry)=0
virtual zlib::Algorithms GetCompressionAlgorithm() const =0
virtual bool Initialize()
Definition: sync_union.cc:24
virtual void PreprocessSyncItem(SharedPtr< SyncItem > entry) const
Definition: sync_union.cc:47
virtual void Touch(SharedPtr< SyncItem > entry)=0
virtual bool IsOpaqueDirectory(SharedPtr< SyncItem > directory) const =0
virtual void RegisterUnionEngine(SyncUnion *engine)=0
virtual bool IsExternalData() const =0
virtual std::string UnwindWhiteoutFilename(SharedPtr< SyncItem > entry) const =0
SharedPtr< SyncItem > CreateSyncItem(const std::string &relative_parent_path, const std::string &filename, const SyncItemType entry_type) const
Definition: sync_union.cc:30
virtual void ProcessSymlink(const std::string &parent_dir, const std::string &link_name)
Definition: sync_union.cc:107
AbstractSyncMediator * mediator_
Definition: sync_union.h:147
void ProcessBlockDevice(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:157
virtual bool IgnoreFilePredicate(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:57
void ProcessSocket(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:175
virtual void ProcessRegularFile(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:99
virtual bool IsDirectIo() const =0
SyncUnion(AbstractSyncMediator *mediator, const std::string &rdonly_path, const std::string &union_path, const std::string &scratch_path)
Definition: sync_union.cc:14
virtual void Add(SharedPtr< SyncItem > entry)=0
void ProcessFile(SharedPtr< SyncItem > entry)
Definition: sync_union.cc:116
virtual bool IsWhiteoutEntry(SharedPtr< SyncItem > entry) const =0
SyncItemType
Definition: sync_item.h:29
virtual void Remove(SharedPtr< SyncItem > entry)=0
virtual bool ProcessDirectory(const std::string &parent_dir, const std::string &dir_name)
const int kLogVerboseMsg
virtual void EnterDirectory(SharedPtr< SyncItem > entry)=0
virtual void EnterDirectory(const std::string &parent_dir, const std::string &dir_name)
Definition: sync_union.cc:135
void ProcessFifo(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:167
void ProcessCharacterDevice(const std::string &parent_dir, const std::string &filename)
Definition: sync_union.cc:147