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 std::string &to_delete,
35  const bool create_catalog_on_root);
36 
38 
39  /*
40  * Check that the tarball is actually valid and that can be open.
41  */
42  bool Initialize();
43 
44  /*
45  * We start by deleting the entity that we are request to delete.
46  * Then we move on to extracting the tarball.
47  * For each directory we found we remember it associated with its SyncItem on
48  * the `dirs_` map.
49  * Similarly we remember where nested catalogs should be placed in
50  * `to_create_catalog_dirs_`.
51  * After we finish to uncompress the tarball we come back to iterate over
52  * `to_create_catalog_dirs_` and we created the nested catalogs.
53  */
54  void Traverse();
55 
56  void PostUpload();
57 
58  std::string UnwindWhiteoutFilename(SharedPtr<SyncItem> entry) const;
59  bool IsOpaqueDirectory(SharedPtr<SyncItem> directory) const;
60  bool IsWhiteoutEntry(SharedPtr<SyncItem> entry) const;
61 
62  private:
63  struct archive *src;
64  const std::string tarball_path_;
65  const std::string base_directory_;
66  const std::string to_delete_;
68  std::set<std::string>
70 
75  std::set<std::string> to_create_catalog_dirs_;
76 
81  std::map<std::string, SharedPtr<SyncItem> > dirs_;
82 
87  std::map<const std::string, std::list<std::string> > hardlinks_;
88 
93 
94  static const size_t kBlockSize = 4096 * 4;
95 
107  void CreateDirectories(const std::string &target);
108  void ProcessArchiveEntry(struct archive_entry *entry);
109  std::string SanitizePath(const std::string &path);
110 }; // class SyncUnionTarball
111 
112 } // namespace publish
113 
114 #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_
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
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)
std::string rdonly_path() const
Definition: sync_union.h:96