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));
117 for (vector<string>::iterator s = to_eliminate_vec.begin();
118 s != to_eliminate_vec.end(); ++s) {
119 std::string parent_path;
120 std::string filename;
122 if (parent_path ==
".") parent_path =
"";
130 if (NULL ==
src)
return;
132 struct archive_entry *entry = archive_entry_new();
137 int result = archive_read_next_header2(
src, entry);
140 case ARCHIVE_FATAL: {
142 archive_error_string(
src));
146 case ARCHIVE_RETRY: {
148 "Error in reading the header, retrying.\n%s\n",
149 archive_error_string(
src));
166 assert(to_mark->IsDirectory());
167 to_mark->SetCatalogMarker();
168 to_mark->MakePlaceholderDirectory();
177 "Warning in uncompression reading, going on.\n %s",
178 archive_error_string(
src));
191 result, archive_error_string(
src));
198 std::string archive_file_path(archive_entry_pathname(entry));
201 std::string complete_path =
206 std::string parent_path;
207 std::string filename;
208 SplitPath(complete_path, &parent_path, &filename);
209 if (parent_path ==
".") parent_path.clear();
214 parent_path, filename,
src, entry,
217 if (NULL != archive_entry_hardlink(entry)) {
218 const std::string hardlink_name(
225 hardlinks_.find(hardlink)->second.push_back(complete_path);
227 std::list<std::string> to_hardlink;
228 to_hardlink.push_back(complete_path);
231 if (filename ==
".cvmfscatalog") {
239 if (sync_entry->IsDirectory()) {
241 sync_entry->MakePlaceholderDirectory();
244 dirs_[complete_path] = sync_entry;
250 }
else if (sync_entry->IsRegularFile()) {
253 if (filename ==
".cvmfscatalog") {
257 }
else if (sync_entry->IsSymlink() || sync_entry->IsFifo() ||
258 sync_entry->IsSocket() || sync_entry->IsCharacterDevice() ||
259 sync_entry->IsBlockDevice()) {
262 if (filename !=
".cvmfscatalog") {
266 "Found entity called as a catalog marker '%s' that however is "
267 "not a regular file, abort",
268 complete_path.c_str());
286 if (path.length() >= 2) {
287 if (path[0] ==
'.' && path[1] ==
'/') {
288 return path.substr(2);
291 if (path.length() >= 1) {
292 if (path[0] ==
'/') {
293 return path.substr(1);
300 std::map<const std::string, std::list<std::string> >::iterator hardlink;
303 std::list<std::string>::iterator entry;
304 for (entry = hardlink->second.begin(); entry != hardlink->second.end();
313 return entry->filename();
333 if (target ==
".")
return;
335 std::string dirname =
"";
336 std::string filename =
"";
340 if (dirname ==
".") dirname =
"";
345 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,...)