1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
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> |
23 |
|
|
class CatalogDiffTool { |
24 |
|
|
public: |
25 |
|
|
CatalogDiffTool(RoCatalogMgr* old_catalog_mgr, RoCatalogMgr* new_catalog_mgr) |
26 |
|
|
: repo_path_(""), |
27 |
|
|
temp_dir_prefix_(""), |
28 |
|
|
download_manager_(NULL), |
29 |
|
|
old_catalog_mgr_(old_catalog_mgr), |
30 |
|
|
new_catalog_mgr_(new_catalog_mgr), |
31 |
|
|
needs_setup_(false) {} |
32 |
|
|
|
33 |
|
1 |
CatalogDiffTool(const std::string& repo_path, const shash::Any& old_root_hash, |
34 |
|
|
const shash::Any& new_root_hash, |
35 |
|
|
const std::string& temp_dir_prefix, |
36 |
|
|
download::DownloadManager* download_manager) |
37 |
|
|
: repo_path_(repo_path), |
38 |
|
|
old_root_hash_(old_root_hash), |
39 |
|
|
new_root_hash_(new_root_hash), |
40 |
|
|
temp_dir_prefix_(temp_dir_prefix), |
41 |
|
|
download_manager_(download_manager), |
42 |
|
|
old_raii_temp_dir_(), |
43 |
|
|
new_raii_temp_dir_(), |
44 |
|
|
old_catalog_mgr_(), |
45 |
|
|
new_catalog_mgr_(), |
46 |
|
1 |
needs_setup_(true) {} |
47 |
|
|
|
48 |
✓✗✗✗
|
1 |
virtual ~CatalogDiffTool() {} |
49 |
|
|
|
50 |
|
|
bool Init(); |
51 |
|
|
|
52 |
|
|
bool Run(const PathString& path); |
53 |
|
|
|
54 |
|
|
protected: |
55 |
|
|
virtual void ReportAddition(const PathString& path, |
56 |
|
|
const catalog::DirectoryEntry& entry, |
57 |
|
|
const XattrList& xattrs, |
58 |
|
|
const FileChunkList& chunks) = 0; |
59 |
|
|
virtual void ReportRemoval(const PathString& path, |
60 |
|
|
const catalog::DirectoryEntry& entry) = 0; |
61 |
|
|
virtual void ReportModification(const PathString& path, |
62 |
|
|
const catalog::DirectoryEntry& old_entry, |
63 |
|
|
const catalog::DirectoryEntry& new_entry, |
64 |
|
|
const XattrList& xattrs, |
65 |
|
|
const FileChunkList& chunks) = 0; |
66 |
|
|
|
67 |
|
|
const catalog::Catalog* GetOldCatalog() const { |
68 |
|
|
return old_catalog_mgr_->GetRootCatalog(); |
69 |
|
|
} |
70 |
|
|
const catalog::Catalog* GetNewCatalog() const { |
71 |
|
|
return new_catalog_mgr_->GetRootCatalog(); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
private: |
75 |
|
|
RoCatalogMgr* OpenCatalogManager(const std::string& repo_path, |
76 |
|
|
const std::string& temp_dir, |
77 |
|
|
const shash::Any& root_hash, |
78 |
|
|
download::DownloadManager* download_manager, |
79 |
|
|
perf::Statistics* stats); |
80 |
|
|
|
81 |
|
|
void DiffRec(const PathString& path); |
82 |
|
|
|
83 |
|
|
std::string repo_path_; |
84 |
|
|
shash::Any old_root_hash_; |
85 |
|
|
shash::Any new_root_hash_; |
86 |
|
|
std::string temp_dir_prefix_; |
87 |
|
|
|
88 |
|
|
download::DownloadManager* download_manager_; |
89 |
|
|
|
90 |
|
|
perf::Statistics stats_old_; |
91 |
|
|
perf::Statistics stats_new_; |
92 |
|
|
|
93 |
|
|
UniquePtr<RaiiTempDir> old_raii_temp_dir_; |
94 |
|
|
UniquePtr<RaiiTempDir> new_raii_temp_dir_; |
95 |
|
|
|
96 |
|
|
UniquePtr<RoCatalogMgr> old_catalog_mgr_; |
97 |
|
|
UniquePtr<RoCatalogMgr> new_catalog_mgr_; |
98 |
|
|
|
99 |
|
|
const bool needs_setup_; |
100 |
|
|
}; |
101 |
|
|
|
102 |
|
|
#include "catalog_diff_tool_impl.h" |
103 |
|
|
|
104 |
|
|
#endif // CVMFS_CATALOG_DIFF_TOOL_H_ |