Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
|
6 |
|
|
#include "publish/repository.h" |
7 |
|
|
|
8 |
|
|
#include <cassert> |
9 |
|
|
#include <string> |
10 |
|
|
|
11 |
|
|
#include "catalog_counters.h" |
12 |
|
|
#include "catalog_diff_tool.h" |
13 |
|
|
#include "catalog_mgr_ro.h" |
14 |
|
|
#include "crypto/hash.h" |
15 |
|
|
#include "file_chunk.h" |
16 |
|
|
#include "history_sqlite.h" |
17 |
|
|
#include "publish/except.h" |
18 |
|
|
#include "shortstring.h" |
19 |
|
|
#include "statistics.h" |
20 |
|
|
#include "xattr.h" |
21 |
|
|
|
22 |
|
|
namespace { |
23 |
|
|
|
24 |
|
✗ |
static history::History::Tag GetTag(const std::string &tag_name, |
25 |
|
|
const history::History &history) |
26 |
|
|
{ |
27 |
|
✗ |
assert(!tag_name.empty()); |
28 |
|
|
|
29 |
|
✗ |
history::History::Tag tag; |
30 |
|
|
|
31 |
|
✗ |
if (tag_name[0] == publish::Repository::kRawHashSymbol) { |
32 |
|
✗ |
tag.name = tag_name.substr(1); |
33 |
|
✗ |
tag.root_hash = |
34 |
|
✗ |
shash::MkFromHexPtr(shash::HexPtr(tag.name), shash::kSuffixCatalog); |
35 |
|
|
} else { |
36 |
|
✗ |
bool retval = history.GetByName(tag_name, &tag); |
37 |
|
✗ |
if (!retval) |
38 |
|
✗ |
throw publish::EPublish("unknown repository tag name: " + tag_name); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
✗ |
return tag; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
class DiffForwarder : public CatalogDiffTool<catalog::SimpleCatalogManager> { |
46 |
|
|
private: |
47 |
|
|
publish::DiffListener *listener_; |
48 |
|
|
|
49 |
|
|
public: |
50 |
|
✗ |
DiffForwarder(catalog::SimpleCatalogManager *old_mgr, |
51 |
|
|
catalog::SimpleCatalogManager *new_mgr, |
52 |
|
|
publish::DiffListener *listener) |
53 |
|
✗ |
: CatalogDiffTool<catalog::SimpleCatalogManager>(old_mgr, new_mgr) |
54 |
|
✗ |
, listener_(listener) |
55 |
|
|
{ |
56 |
|
|
} |
57 |
|
✗ |
virtual ~DiffForwarder() {} |
58 |
|
|
|
59 |
|
✗ |
virtual void ReportAddition(const PathString& path, |
60 |
|
|
const catalog::DirectoryEntry& entry, |
61 |
|
|
const XattrList& /* xattrs */, |
62 |
|
|
const FileChunkList& /* chunks */) |
63 |
|
|
{ |
64 |
|
✗ |
listener_->OnAdd(path.ToString(), entry); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
✗ |
virtual void ReportRemoval(const PathString& path, |
68 |
|
|
const catalog::DirectoryEntry& entry) |
69 |
|
|
{ |
70 |
|
✗ |
listener_->OnRemove(path.ToString(), entry); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
✗ |
virtual bool ReportModification(const PathString& path, |
74 |
|
|
const catalog::DirectoryEntry& old_entry, |
75 |
|
|
const catalog::DirectoryEntry& new_entry, |
76 |
|
|
const XattrList& /*xattrs */, |
77 |
|
|
const FileChunkList& /* chunks */) |
78 |
|
|
{ |
79 |
|
✗ |
listener_->OnModify(path.ToString(), old_entry, new_entry); |
80 |
|
✗ |
return true; |
81 |
|
|
} |
82 |
|
|
}; // class DiffForwarder |
83 |
|
|
|
84 |
|
|
} // anonymous namespace |
85 |
|
|
|
86 |
|
|
namespace publish { |
87 |
|
|
|
88 |
|
✗ |
void Repository::Diff(const std::string &from, const std::string &to, |
89 |
|
|
DiffListener *diff_listener) |
90 |
|
|
{ |
91 |
|
✗ |
history::History::Tag from_tag = GetTag(from, *history_); |
92 |
|
✗ |
history::History::Tag to_tag = GetTag(to, *history_); |
93 |
|
✗ |
diff_listener->OnInit(from_tag, to_tag); |
94 |
|
|
|
95 |
|
✗ |
perf::Statistics stats_from; |
96 |
|
|
catalog::SimpleCatalogManager *mgr_from = new catalog::SimpleCatalogManager( |
97 |
|
|
from_tag.root_hash, |
98 |
|
✗ |
settings_.url(), |
99 |
|
✗ |
settings_.tmp_dir(), |
100 |
|
|
download_mgr_, |
101 |
|
|
&stats_from, |
102 |
|
✗ |
true /* manage_catalog_files */); |
103 |
|
✗ |
mgr_from->Init(); |
104 |
|
|
|
105 |
|
✗ |
perf::Statistics stats_to; |
106 |
|
|
catalog::SimpleCatalogManager *mgr_to = new catalog::SimpleCatalogManager( |
107 |
|
|
to_tag.root_hash, |
108 |
|
✗ |
settings_.url(), |
109 |
|
✗ |
settings_.tmp_dir(), |
110 |
|
|
download_mgr_, |
111 |
|
|
&stats_to, |
112 |
|
✗ |
true /* manage_catalog_files */); |
113 |
|
✗ |
mgr_to->Init(); |
114 |
|
|
|
115 |
|
✗ |
catalog::Counters counters_from = mgr_from->GetRootCatalog()->GetCounters(); |
116 |
|
✗ |
catalog::Counters counters_to = mgr_to->GetRootCatalog()->GetCounters(); |
117 |
|
✗ |
diff_listener->OnStats(catalog::Counters::Diff(counters_from, counters_to)); |
118 |
|
|
|
119 |
|
|
// DiffTool takes ownership of the catalog managers |
120 |
|
✗ |
DiffForwarder diff_forwarder(mgr_from, mgr_to, diff_listener); |
121 |
|
✗ |
if (!diff_forwarder.Init()) |
122 |
|
✗ |
throw EPublish("cannot initialize difference engine"); |
123 |
|
✗ |
diff_forwarder.Run(PathString()); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
} // namespace publish |
127 |
|
|
|