5 #define __STDC_FORMAT_MACROS
34 const std::string &rdonly_path,
35 const std::string &tarball_path,
36 const std::string &base_directory,
39 const std::string &to_delete,
40 const bool create_catalog_on_root,
41 const std::string &path_delimiter)
42 :
SyncUnion(mediator, rdonly_path,
"",
"")
44 , tarball_path_(tarball_path)
45 , base_directory_(base_directory)
48 , to_delete_(to_delete)
49 , create_catalog_on_root_(create_catalog_on_root)
50 , path_delimiter_(path_delimiter)
51 , read_archive_signal_(new
Signal) { }
64 src = archive_read_new();
65 assert(ARCHIVE_OK == archive_read_support_format_tar(
src));
66 assert(ARCHIVE_OK == archive_read_support_format_empty(
src));
72 result = archive_read_open_filename(
src, tarball_absolute_path.c_str(),
76 if (result != ARCHIVE_OK) {
78 archive_error_string(
src));
118 for (vector<string>::iterator s = to_eliminate_vec.begin();
119 s != to_eliminate_vec.end();
121 std::string parent_path;
122 std::string filename;
124 if (parent_path ==
".")
136 struct archive_entry *entry = archive_entry_new();
141 int result = archive_read_next_header2(
src, entry);
144 case ARCHIVE_FATAL: {
146 archive_error_string(
src));
150 case ARCHIVE_RETRY: {
152 "Error in reading the header, retrying.\n%s\n",
153 archive_error_string(
src));
171 assert(to_mark->IsDirectory());
172 to_mark->SetCatalogMarker();
173 to_mark->MakePlaceholderDirectory();
182 "Warning in uncompression reading, going on.\n %s",
183 archive_error_string(
src));
196 result, archive_error_string(
src));
203 std::string archive_file_path(archive_entry_pathname(entry));
211 std::string parent_path;
212 std::string filename;
213 SplitPath(complete_path, &parent_path, &filename);
214 if (parent_path ==
".")
223 if (NULL != archive_entry_hardlink(entry)) {
224 const std::string hardlink_name(
231 hardlinks_.find(hardlink)->second.push_back(complete_path);
233 std::list<std::string> to_hardlink;
234 to_hardlink.push_back(complete_path);
237 if (filename ==
".cvmfscatalog") {
245 if (sync_entry->IsDirectory()) {
247 sync_entry->MakePlaceholderDirectory();
250 dirs_[complete_path] = sync_entry;
256 }
else if (sync_entry->IsRegularFile()) {
259 if (filename ==
".cvmfscatalog") {
263 }
else if (sync_entry->IsSymlink() || sync_entry->IsFifo()
264 || sync_entry->IsSocket() || sync_entry->IsCharacterDevice()
265 || sync_entry->IsBlockDevice()) {
268 if (filename !=
".cvmfscatalog") {
272 "Found entity called as a catalog marker '%s' that however is "
273 "not a regular file, abort",
274 complete_path.c_str());
292 if (path.length() >= 2) {
293 if (path[0] ==
'.' && path[1] ==
'/') {
294 return path.substr(2);
297 if (path.length() >= 1) {
298 if (path[0] ==
'/') {
299 return path.substr(1);
306 std::map<const std::string, std::list<std::string> >::iterator hardlink;
309 std::list<std::string>::iterator entry;
310 for (entry = hardlink->second.begin(); entry != hardlink->second.end();
319 return entry->filename();
343 std::string dirname =
"";
344 std::string filename =
"";
354 dirs_[target] = dummy;
std::map< const std::string, std::list< std::string > > hardlinks_
virtual bool ProcessUnmaterializedDirectory(SharedPtr< SyncItem > entry)
bool IsOpaqueDirectory(SharedPtr< SyncItem > directory) const
std::map< std::string, SharedPtr< SyncItem > > dirs_
const std::string base_directory_
virtual bool Initialize()
assert((mem||(size==0))&&"Out Of Memory")
std::string UnwindWhiteoutFilename(SharedPtr< SyncItem > entry) const
void CreateDirectories(const std::string &target)
SharedPtr< SyncItem > CreateSyncItem(const std::string &relative_parent_path, const std::string &filename, const SyncItemType entry_type) const
const std::string tarball_path_
std::set< std::string > to_create_catalog_dirs_
SyncUnionTarball(AbstractSyncMediator *mediator, const std::string &rdonly_path, const std::string &tarball_path, const std::string &base_directory, const uid_t uid, const gid_t gid, const std::string &to_delete, const bool create_catalog_on_root, const std::string &path_delimiter=":")
std::string GetAbsolutePath(const std::string &path)
void SplitPath(const std::string &path, std::string *dirname, std::string *filename)
AbstractSyncMediator * mediator_
bool IsInitialized() const
std::string SanitizePath(const std::string &path)
Signal * read_archive_signal_
const std::string to_delete_
entity to delete before to extract the tar
vector< string > SplitStringMultiChar(const string &str, const string &delim)
void ProcessArchiveEntry(struct archive_entry *entry)
void ProcessFile(SharedPtr< SyncItem > entry)
const bool create_catalog_on_root_
virtual bool ProcessDirectory(const std::string &parent_dir, const std::string &dir_name)
static const size_t kBlockSize
const std::string path_delimiter_
delimiter used to split paths
bool IsWhiteoutEntry(SharedPtr< SyncItem > entry) const
std::set< std::string > know_directories_
directory that we know already exist
std::string MakeCanonicalPath(const std::string &path)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)