CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sync_union_tarball.h
Go to the documentation of this file.
1 
9 #ifndef CVMFS_SYNC_UNION_TARBALL_H_
10 #define CVMFS_SYNC_UNION_TARBALL_H_
11 
12 #include "sync_union.h"
13 
14 #include <pthread.h>
15 
16 #include <list>
17 #include <map>
18 #include <set>
19 #include <string>
20 
21 #include "duplex_libarchive.h"
22 #include "util/concurrency.h"
23 
24 namespace publish {
25 
26 class AbstractSyncMediator;
27 
28 class SyncUnionTarball : public SyncUnion {
29  public:
31  const std::string &rdonly_path,
32  const std::string &tarball_path,
33  const std::string &base_directory,
34  const uid_t uid,
35  const gid_t gid,
36  const std::string &to_delete,
37  const bool create_catalog_on_root);
38 
40 
41  /*
42  * Check that the tarball is actually valid and that can be open.
43  */
44  bool Initialize();
45 
46  /*
47  * We start by deleting the entity that we are request to delete.
48  * Then we move on to extracting the tarball.
49  * For each directory we found we remember it associated with its SyncItem on
50  * the `dirs_` map.
51  * Similarly we remember where nested catalogs should be placed in
52  * `to_create_catalog_dirs_`.
53  * After we finish to uncompress the tarball we come back to iterate over
54  * `to_create_catalog_dirs_` and we created the nested catalogs.
55  */
56  void Traverse();
57 
58  void PostUpload();
59 
60  std::string UnwindWhiteoutFilename(SharedPtr<SyncItem> entry) const;
61  bool IsOpaqueDirectory(SharedPtr<SyncItem> directory) const;
62  bool IsWhiteoutEntry(SharedPtr<SyncItem> entry) const;
63 
64  private:
65  struct archive *src;
66  const std::string tarball_path_;
67  const std::string base_directory_;
68  const uid_t uid_;
69  const gid_t gid_;
70  const std::string to_delete_;
72  std::set<std::string>
74 
79  std::set<std::string> to_create_catalog_dirs_;
80 
85  std::map<std::string, SharedPtr<SyncItem> > dirs_;
86 
91  std::map<const std::string, std::list<std::string> > hardlinks_;
92 
97 
98  static const size_t kBlockSize = 4096 * 4;
99 
111  void CreateDirectories(const std::string &target);
112  void ProcessArchiveEntry(struct archive_entry *entry);
113  std::string SanitizePath(const std::string &path);
114 }; // class SyncUnionTarball
115 
116 } // namespace publish
117 
118 #endif // CVMFS_SYNC_UNION_TARBALL_H_
std::map< const std::string, std::list< std::string > > hardlinks_
bool IsOpaqueDirectory(SharedPtr< SyncItem > directory) const
std::map< std::string, SharedPtr< SyncItem > > dirs_
const std::string base_directory_
std::string UnwindWhiteoutFilename(SharedPtr< SyncItem > entry) const
void CreateDirectories(const std::string &target)
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)
std::string SanitizePath(const std::string &path)
const std::string to_delete_
entity to delete before to extract the tar
void ProcessArchiveEntry(struct archive_entry *entry)
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 rdonly_path() const
Definition: sync_union.h:96