CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_diff_tool.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_CATALOG_DIFF_TOOL_H_
6 #define CVMFS_CATALOG_DIFF_TOOL_H_
7 
8 #include <string>
9 
10 #include "directory_entry.h"
11 #include "file_chunk.h"
12 #include "shortstring.h"
13 #include "statistics.h"
14 #include "util/pointer.h"
15 #include "util/raii_temp_dir.h"
16 #include "xattr.h"
17 
18 namespace download {
19 class DownloadManager;
20 }
21 
22 template<typename RoCatalogMgr>
24  public:
25  CatalogDiffTool(RoCatalogMgr *old_catalog_mgr, RoCatalogMgr *new_catalog_mgr)
26  : repo_path_("")
27  , temp_dir_prefix_("")
28  , download_manager_(NULL)
29  , cache_dir_("")
30  , old_catalog_mgr_(old_catalog_mgr)
31  , new_catalog_mgr_(new_catalog_mgr)
32  , needs_setup_(false) { }
33 
34  CatalogDiffTool(const std::string &repo_path,
35  const shash::Any &old_root_hash,
36  const shash::Any &new_root_hash,
37  const std::string &temp_dir_prefix,
38  download::DownloadManager *download_manager,
39  const std::string &cache_dir = "")
40  : repo_path_(repo_path)
41  , old_root_hash_(old_root_hash)
42  , new_root_hash_(new_root_hash)
43  , temp_dir_prefix_(temp_dir_prefix)
44  , download_manager_(download_manager)
45  , cache_dir_(cache_dir)
50  , needs_setup_(true) { }
51 
52  virtual ~CatalogDiffTool() { }
53 
54  bool Init();
55 
56  bool Run(const PathString &path);
57 
58  protected:
67  virtual bool IsIgnoredPath(const PathString & /* path */) { return false; }
68 
92  virtual bool IsReportablePath(const PathString & /* path */) { return true; }
93 
94  // Note that addition and modification can return false to indicate that
95  // the recursion stops. In the merge tool, this happens at nested catalog
96  // transition points:
97  // - For a new directory that is a nested catalog, we don't need to recurse
98  // further but just install that nested catalog in the parent
99  // - When a nested catalog is replaced, we likewise do not need to recurse
100  // further into the new nested catalog tree.
101 
102  virtual bool ReportAddition(const PathString &path,
103  const catalog::DirectoryEntry &entry,
104  const XattrList &xattrs,
105  const FileChunkList &chunks) = 0;
106  virtual void ReportRemoval(const PathString &path,
107  const catalog::DirectoryEntry &entry) = 0;
108  virtual bool ReportModification(const PathString &path,
109  const catalog::DirectoryEntry &old_entry,
110  const catalog::DirectoryEntry &new_entry,
111  const XattrList &xattrs,
112  const FileChunkList &chunks) = 0;
113 
115  return old_catalog_mgr_->GetRootCatalog();
116  }
118  return new_catalog_mgr_->GetRootCatalog();
119  }
120  RoCatalogMgr *GetOldCatalogMgr() { return old_catalog_mgr_.weak_ref(); }
121  RoCatalogMgr *GetNewCatalogMgr() { return new_catalog_mgr_.weak_ref(); }
122 
123  private:
124  RoCatalogMgr *OpenCatalogManager(const std::string &repo_path,
125  const std::string &temp_dir,
126  const shash::Any &root_hash,
127  download::DownloadManager *download_manager,
128  perf::Statistics *stats,
129  const std::string &cache_dir);
130 
131  void DiffRec(const PathString &path);
132 
133  std::string repo_path_;
136  std::string temp_dir_prefix_;
137 
139  const std::string cache_dir_; // path if local caching of catalogs
140 
143 
146 
149 
150  const bool needs_setup_;
151 };
152 
153 #include "catalog_diff_tool_impl.h"
154 
155 #endif // CVMFS_CATALOG_DIFF_TOOL_H_
download::DownloadManager * download_manager_
UniquePtr< RoCatalogMgr > new_catalog_mgr_
perf::Statistics stats_new_
const std::string cache_dir_
std::string temp_dir_prefix_
virtual ~CatalogDiffTool()
const catalog::Catalog * GetNewCatalog() const
T * weak_ref() const
Definition: pointer.h:46
CatalogDiffTool(const std::string &repo_path, const shash::Any &old_root_hash, const shash::Any &new_root_hash, const std::string &temp_dir_prefix, download::DownloadManager *download_manager, const std::string &cache_dir="")
void DiffRec(const PathString &path)
UniquePtr< RoCatalogMgr > old_catalog_mgr_
shash::Any old_root_hash_
virtual bool IsReportablePath(const PathString &)
std::string repo_path_
RoCatalogMgr * OpenCatalogManager(const std::string &repo_path, const std::string &temp_dir, const shash::Any &root_hash, download::DownloadManager *download_manager, perf::Statistics *stats, const std::string &cache_dir)
virtual bool ReportModification(const PathString &path, const catalog::DirectoryEntry &old_entry, const catalog::DirectoryEntry &new_entry, const XattrList &xattrs, const FileChunkList &chunks)=0
RoCatalogMgr * GetNewCatalogMgr()
RoCatalogMgr * GetOldCatalogMgr()
UniquePtr< RaiiTempDir > new_raii_temp_dir_
virtual bool ReportAddition(const PathString &path, const catalog::DirectoryEntry &entry, const XattrList &xattrs, const FileChunkList &chunks)=0
virtual bool IsIgnoredPath(const PathString &)
perf::Statistics stats_old_
const bool needs_setup_
virtual void ReportRemoval(const PathString &path, const catalog::DirectoryEntry &entry)=0
shash::Any new_root_hash_
bool Run(const PathString &path)
const catalog::Catalog * GetOldCatalog() const
CatalogDiffTool(RoCatalogMgr *old_catalog_mgr, RoCatalogMgr *new_catalog_mgr)
UniquePtr< RaiiTempDir > old_raii_temp_dir_