5 #ifndef CVMFS_RECEIVER_CATALOG_MERGE_TOOL_IMPL_H_
6 #define CVMFS_RECEIVER_CATALOG_MERGE_TOOL_IMPL_H_
23 std::string abs_path = path.
ToString();
24 if (abs_path[0] ==
'/') {
25 rel_path = abs_path.substr(1);
35 "CatalogMergeTool - Hardlink found: %s. Hardlinks are not "
36 "supported when publishing through repository gateway and "
45 "CatalogMergeTool - Removal of file %s with linkcount > 1 is "
46 "not supported. Aborting",
53 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
55 const Params& params, std::string* new_manifest_path,
shash::Any* new_manifest_hash, uint64_t *final_rev) {
66 "dummy_token",
"dummy_key");
67 spooler = upload::Spooler::Construct(definition, &stats_tmpl);
68 const std::string
temp_dir = raii_temp_dir->dir();
69 output_catalog_mgr_ =
new RwCatalogMgr(
75 output_catalog_mgr_->Init();
80 ret &= CreateNewManifest(new_manifest_path);
84 output_catalog_mgr_.Destroy();
89 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
96 return !(
IsSubPath(lease_path_, rel_path) ||
100 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
110 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
116 const std::string parent_path =
122 RoCatalogMgr *new_catalog_mgr =
126 uint64_t nested_size;
127 const bool found = new_catalog_mgr->LookupNested(
128 path, &mountpoint, &nested_hash, &nested_size);
129 if (!found || !nested_size) {
131 "CatalogMergeTool - nested catalog %s not found. Aborting",
134 output_catalog_mgr_->GraftNestedCatalog(rel_path.
ToString(),
135 nested_hash, nested_size);
138 output_catalog_mgr_->AddDirectory(entry, xattrs, parent_path);
140 perf::Inc(counters_->n_directories_added);
148 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
151 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
158 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry.
size()));
163 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
170 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()),
174 output_catalog_mgr_->RemoveDirectory(rel_path.
c_str());
175 perf::Inc(counters_->n_directories_removed);
178 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
181 perf::Inc(counters_->n_symlinks_removed);
186 perf::Xadd(counters_->sz_removed_bytes, static_cast<int64_t>(entry.
size()));
190 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
197 const std::string parent_path =
203 RoCatalogMgr *new_catalog_mgr =
208 const bool found = new_catalog_mgr->LookupNested(path, &mountpoint,
209 &new_hash, &new_size);
210 if (!found || !new_size) {
212 "CatalogMergeTool - nested catalog %s not found. Aborting",
215 output_catalog_mgr_->SwapNestedCatalog(rel_path.
ToString(), new_hash,
222 output_catalog_mgr_->TouchDirectory(*base_entry, xattrs, rel_path.
c_str());
225 output_catalog_mgr_->CreateNestedCatalog(std::string(rel_path.
c_str()));
228 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()));
230 perf::Inc(counters_->n_directories_changed);
234 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
235 output_catalog_mgr_->AddDirectory(entry2, xattrs, parent_path);
237 output_catalog_mgr_->CreateNestedCatalog(std::string(rel_path.
c_str()));
240 perf::Inc(counters_->n_symlinks_removed);
245 static_cast<int64_t>(entry1.
size()));
246 perf::Inc(counters_->n_directories_added);
253 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()),
262 output_catalog_mgr_->RemoveDirectory(rel_path.
c_str());
266 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
269 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
272 perf::Inc(counters_->n_directories_removed);
278 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry2.
size()));
288 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
291 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
294 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
303 perf::Inc(counters_->n_symlinks_removed);
306 perf::Inc(counters_->n_symlinks_changed);
309 static_cast<int64_t>(entry1.
size()));
310 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry2.
size()));
315 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
317 std::string* new_manifest_path) {
318 if (!output_catalog_mgr_->Commit(
false, 0,
manifest_)) {
320 "CatalogMergeTool - Could not commit output catalog");
324 const std::string new_path =
CreateTempPath(temp_dir_prefix_, 0600);
328 "CatalogMergeTool - Could not export new manifest");
331 *new_manifest_path = new_path;
338 #endif // CVMFS_RECEIVER_CATALOG_MERGE_TOOL_IMPL_H_
uint32_t linkcount() const
bool IsSubPath(const PathString &parent, const PathString &path)
bool Export(const std::string &path) const
int64_t Xadd(class Counter *counter, const int64_t delta)
SharedPtr< string > temp_dir
std::string spooler_configuration
bool IsChunkedFile() const
void set_linkcount(const uint32_t linkcount)
zlib::Algorithms compression_alg
size_t nested_kcatalog_limit
perf::Statistics * statistics_
std::string CreateTempPath(const std::string &path_prefix, const int mode)
assert((mem||(size==0))&&"Out Of Memory")
upload::Spooler * spooler
bool IsNestedCatalogMountpoint() const
uint64_t revision() const
static RaiiTempDir * Create(const std::string &prefix)
shash::Any catalog_hash() const
void Inc(class Counter *counter)
manifest::Manifest * manifest_
std::string ToString() const
ShortString< kDefaultMaxPath, 0 > PathString
PathString GetParentPath(const PathString &path)
size_t root_kcatalog_limit
bool generate_legacy_bulk_chunks
const char * c_str() const
shash::Algorithms hash_alg
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)