Directory: | cvmfs/ |
---|---|
File: | cvmfs/catalog_diff_tool.h |
Date: | 2024-04-21 02:33:16 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 12 | 23 | 52.2% |
Branches: | 7 | 34 | 20.6% |
Line | Branch | Exec | Source |
---|---|---|---|
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 | 2 | 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 | 2 | : repo_path_(repo_path), | |
38 | 2 | old_root_hash_(old_root_hash), | |
39 | 2 | new_root_hash_(new_root_hash), | |
40 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | temp_dir_prefix_(temp_dir_prefix), |
41 | 2 | download_manager_(download_manager), | |
42 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | old_raii_temp_dir_(), |
43 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | new_raii_temp_dir_(), |
44 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | old_catalog_mgr_(), |
45 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | new_catalog_mgr_(), |
46 |
2/4✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
6 | needs_setup_(true) {} |
47 | |||
48 | 4 | virtual ~CatalogDiffTool() {} | |
49 | |||
50 | bool Init(); | ||
51 | |||
52 | bool Run(const PathString& path); | ||
53 | |||
54 | protected: | ||
55 | /** | ||
56 | * Check if a path (and, by implication, any subpath) should be | ||
57 | * ignored and not considered for comparison purposes. | ||
58 | * | ||
59 | * This can be used to avoid unnecessary work by avoiding recursion | ||
60 | * into paths that will not be of interest (e.g. paths that are | ||
61 | * neither above nor within the lease path, when using a gateway). | ||
62 | */ | ||
63 | ✗ | virtual bool IsIgnoredPath(const PathString& /* path */) { return false; } | |
64 | |||
65 | /** | ||
66 | * Check if a difference found on a path should be reported via | ||
67 | * ReportAddition(), ReportRemoval(), or ReportModification(). | ||
68 | * | ||
69 | * This can be used to filter out differences that are not of | ||
70 | * interest (e.g. paths that are not within the lease path, when | ||
71 | * using a gateway). | ||
72 | * | ||
73 | * Note that an ignored path must necessarily be a non-reportable | ||
74 | * path, since an ignored path will never even be compared (and so | ||
75 | * can never be reported upon). However, there do exist paths that | ||
76 | * are neither ignored nor reportable: when using a gateway, a | ||
77 | * parent of the lease path is not reportable (since it is not | ||
78 | * within the lease path) but must not be ignored (since we need to | ||
79 | * recurse into the parent path in order to reach the lease path). | ||
80 | * | ||
81 | * As a concrete example, with a lease path of /foo/bar: | ||
82 | * | ||
83 | * /foo <- not ignored, not reportable | ||
84 | * /foo/bar <- not ignored reportable | ||
85 | * /foo/bar/thing <- not ignored reportable | ||
86 | * /foo/baz <- ignored (and therefore not reportable) | ||
87 | */ | ||
88 | ✗ | virtual bool IsReportablePath(const PathString& /* path */) { return true; } | |
89 | |||
90 | virtual void ReportAddition(const PathString& path, | ||
91 | const catalog::DirectoryEntry& entry, | ||
92 | const XattrList& xattrs, | ||
93 | const FileChunkList& chunks) = 0; | ||
94 | virtual void ReportRemoval(const PathString& path, | ||
95 | const catalog::DirectoryEntry& entry) = 0; | ||
96 | virtual bool ReportModification(const PathString& path, | ||
97 | const catalog::DirectoryEntry& old_entry, | ||
98 | const catalog::DirectoryEntry& new_entry, | ||
99 | const XattrList& xattrs, | ||
100 | const FileChunkList& chunks) = 0; | ||
101 | |||
102 | const catalog::Catalog* GetOldCatalog() const { | ||
103 | return old_catalog_mgr_->GetRootCatalog(); | ||
104 | } | ||
105 | const catalog::Catalog* GetNewCatalog() const { | ||
106 | return new_catalog_mgr_->GetRootCatalog(); | ||
107 | } | ||
108 | RoCatalogMgr* GetOldCatalogMgr() { | ||
109 | return old_catalog_mgr_.weak_ref(); | ||
110 | } | ||
111 | ✗ | RoCatalogMgr* GetNewCatalogMgr() { | |
112 | ✗ | return new_catalog_mgr_.weak_ref(); | |
113 | } | ||
114 | |||
115 | private: | ||
116 | RoCatalogMgr* OpenCatalogManager(const std::string& repo_path, | ||
117 | const std::string& temp_dir, | ||
118 | const shash::Any& root_hash, | ||
119 | download::DownloadManager* download_manager, | ||
120 | perf::Statistics* stats); | ||
121 | |||
122 | void DiffRec(const PathString& path); | ||
123 | |||
124 | std::string repo_path_; | ||
125 | shash::Any old_root_hash_; | ||
126 | shash::Any new_root_hash_; | ||
127 | std::string temp_dir_prefix_; | ||
128 | |||
129 | download::DownloadManager* download_manager_; | ||
130 | |||
131 | perf::Statistics stats_old_; | ||
132 | perf::Statistics stats_new_; | ||
133 | |||
134 | UniquePtr<RaiiTempDir> old_raii_temp_dir_; | ||
135 | UniquePtr<RaiiTempDir> new_raii_temp_dir_; | ||
136 | |||
137 | UniquePtr<RoCatalogMgr> old_catalog_mgr_; | ||
138 | UniquePtr<RoCatalogMgr> new_catalog_mgr_; | ||
139 | |||
140 | const bool needs_setup_; | ||
141 | }; | ||
142 | |||
143 | #include "catalog_diff_tool_impl.h" | ||
144 | |||
145 | #endif // CVMFS_CATALOG_DIFF_TOOL_H_ | ||
146 |