CernVM-FS  2.12.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  virtual void ReportAddition(const PathString& path,
95  const catalog::DirectoryEntry& entry,
96  const XattrList& xattrs,
97  const FileChunkList& chunks) = 0;
98  virtual void ReportRemoval(const PathString& path,
99  const catalog::DirectoryEntry& entry) = 0;
100  virtual bool ReportModification(const PathString& path,
101  const catalog::DirectoryEntry& old_entry,
102  const catalog::DirectoryEntry& new_entry,
103  const XattrList& xattrs,
104  const FileChunkList& chunks) = 0;
105 
107  return old_catalog_mgr_->GetRootCatalog();
108  }
110  return new_catalog_mgr_->GetRootCatalog();
111  }
112  RoCatalogMgr* GetOldCatalogMgr() {
113  return old_catalog_mgr_.weak_ref();
114  }
115  RoCatalogMgr* GetNewCatalogMgr() {
116  return new_catalog_mgr_.weak_ref();
117  }
118 
119  private:
120  RoCatalogMgr* OpenCatalogManager(const std::string& repo_path,
121  const std::string& temp_dir,
122  const shash::Any& root_hash,
123  download::DownloadManager* download_manager,
124  perf::Statistics* stats,
125  const std::string& cache_dir);
126 
127  void DiffRec(const PathString& path);
128 
129  std::string repo_path_;
132  std::string temp_dir_prefix_;
133 
135  const std::string cache_dir_; // path if local caching of catalogs
136 
139 
142 
145 
146  const bool needs_setup_;
147 };
148 
149 #include "catalog_diff_tool_impl.h"
150 
151 #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:42
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_
virtual void ReportAddition(const PathString &path, const catalog::DirectoryEntry &entry, const XattrList &xattrs, const FileChunkList &chunks)=0
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 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_