5 #define __STDC_FORMAT_MACROS
34 const std::string &rdonly_path,
35 const std::string &tarball_path,
36 const std::string &base_directory,
37 const std::string &to_delete,
38 const bool create_catalog_on_root)
39 :
SyncUnion(mediator, rdonly_path,
"",
""),
41 tarball_path_(tarball_path),
42 base_directory_(base_directory),
43 to_delete_(to_delete),
44 create_catalog_on_root_(create_catalog_on_root),
45 read_archive_signal_(new
Signal) {}
58 src = archive_read_new();
59 assert(ARCHIVE_OK == archive_read_support_format_tar(
src));
60 assert(ARCHIVE_OK == archive_read_support_format_empty(
src));
66 result = archive_read_open_filename(
src, tarball_absolute_path.c_str(),
70 if (result != ARCHIVE_OK) {
110 for (vector<string>::iterator s = to_eliminate_vec.begin();
111 s != to_eliminate_vec.end(); ++s) {
112 std::string parent_path;
113 std::string filename;
115 if (parent_path ==
".") parent_path =
"";
123 if (NULL ==
src)
return;
125 struct archive_entry *entry = archive_entry_new();
130 int result = archive_read_next_header2(
src, entry);
133 case ARCHIVE_FATAL: {
135 archive_error_string(
src));
139 case ARCHIVE_RETRY: {
141 "Error in reading the header, retrying.\n%s\n",
142 archive_error_string(
src));
159 assert(to_mark->IsDirectory());
160 to_mark->SetCatalogMarker();
161 to_mark->MakePlaceholderDirectory();
170 "Warning in uncompression reading, going on.\n %s",
171 archive_error_string(
src));
184 result, archive_error_string(
src));
191 std::string archive_file_path(archive_entry_pathname(entry));
194 std::string complete_path =
199 std::string parent_path;
200 std::string filename;
201 SplitPath(complete_path, &parent_path, &filename);
202 if (parent_path ==
".") parent_path.clear();
209 if (NULL != archive_entry_hardlink(entry)) {
210 const std::string hardlink_name(
217 hardlinks_.find(hardlink)->second.push_back(complete_path);
219 std::list<std::string> to_hardlink;
220 to_hardlink.push_back(complete_path);
223 if (filename ==
".cvmfscatalog") {
231 if (sync_entry->IsDirectory()) {
233 sync_entry->MakePlaceholderDirectory();
236 dirs_[complete_path] = sync_entry;
242 }
else if (sync_entry->IsRegularFile()) {
245 if (filename ==
".cvmfscatalog") {
249 }
else if (sync_entry->IsSymlink() || sync_entry->IsFifo() ||
250 sync_entry->IsSocket() || sync_entry->IsCharacterDevice() ||
251 sync_entry->IsBlockDevice()) {
254 if (filename !=
".cvmfscatalog") {
258 "Found entity called as a catalog marker '%s' that however is "
259 "not a regular file, abort",
260 complete_path.c_str());
278 if (path.length() >= 2) {
279 if (path[0] ==
'.' && path[1] ==
'/') {
280 return path.substr(2);
283 if (path.length() >= 1) {
284 if (path[0] ==
'/') {
285 return path.substr(1);
292 std::map<const std::string, std::list<std::string> >::iterator hardlink;
295 std::list<std::string>::iterator entry;
296 for (entry = hardlink->second.begin(); entry != hardlink->second.end();
305 return entry->filename();
325 if (target ==
".")
return;
327 std::string dirname =
"";
328 std::string filename =
"";
332 if (dirname ==
".") dirname =
"";
337 dirs_[target] = dummy;
#define LogCvmfs(source, mask,...)
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_
std::string GetAbsolutePath(const std::string &path)
void SplitPath(const std::string &path, std::string *dirname, std::string *filename)
AbstractSyncMediator * mediator_
vector< string > SplitString(const string &str, char delim)
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
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
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)
SyncUnionTarball(AbstractSyncMediator *mediator, const std::string &rdonly_path, const std::string &tarball_path, const std::string &base_directory, const std::string &to_delete, const bool create_catalog_on_root)