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, 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 =
120 output_catalog_mgr_->AddDirectory(entry, xattrs, parent_path);
122 output_catalog_mgr_->CreateNestedCatalog(std::string(rel_path.
c_str()));
124 perf::Inc(counters_->n_directories_added);
132 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
135 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
142 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry.
size()));
146 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
153 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()),
157 output_catalog_mgr_->RemoveDirectory(rel_path.
c_str());
158 perf::Inc(counters_->n_directories_removed);
161 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
164 perf::Inc(counters_->n_symlinks_removed);
169 perf::Xadd(counters_->sz_removed_bytes, static_cast<int64_t>(entry.
size()));
173 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
180 const std::string parent_path =
186 RoCatalogMgr *new_catalog_mgr =
191 const bool found = new_catalog_mgr->LookupNested(path, &mountpoint,
192 &new_hash, &new_size);
193 if (!found || !new_size) {
195 "CatalogMergeTool - nested catalog %s not found. Aborting",
198 output_catalog_mgr_->SwapNestedCatalog(rel_path.
ToString(), new_hash,
205 output_catalog_mgr_->TouchDirectory(*base_entry, xattrs, rel_path.
c_str());
208 output_catalog_mgr_->CreateNestedCatalog(std::string(rel_path.
c_str()));
211 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()));
213 perf::Inc(counters_->n_directories_changed);
217 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
218 output_catalog_mgr_->AddDirectory(entry2, xattrs, parent_path);
220 output_catalog_mgr_->CreateNestedCatalog(std::string(rel_path.
c_str()));
223 perf::Inc(counters_->n_symlinks_removed);
228 static_cast<int64_t>(entry1.
size()));
229 perf::Inc(counters_->n_directories_added);
236 output_catalog_mgr_->RemoveNestedCatalog(std::string(rel_path.
c_str()),
245 output_catalog_mgr_->RemoveDirectory(rel_path.
c_str());
249 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
252 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
255 perf::Inc(counters_->n_directories_removed);
261 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry2.
size()));
271 output_catalog_mgr_->RemoveFile(rel_path.
c_str());
274 output_catalog_mgr_->AddChunkedFile(*base_entry, xattrs, parent_path,
277 output_catalog_mgr_->AddFile(*base_entry, xattrs, parent_path);
286 perf::Inc(counters_->n_symlinks_removed);
289 perf::Inc(counters_->n_symlinks_changed);
292 static_cast<int64_t>(entry1.
size()));
293 perf::Xadd(counters_->sz_added_bytes, static_cast<int64_t>(entry2.
size()));
298 template <
typename RwCatalogMgr,
typename RoCatalogMgr>
300 std::string* new_manifest_path) {
301 if (!output_catalog_mgr_->Commit(
false, 0,
manifest_)) {
303 "CatalogMergeTool - Could not commit output catalog");
307 const std::string new_path =
CreateTempPath(temp_dir_prefix_, 0600);
311 "CatalogMergeTool - Could not export new manifest");
314 *new_manifest_path = new_path;
321 #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,...)