GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/repository_diff.cc
Date: 2025-04-20 02:34:28
Exec Total Coverage
Lines: 0 44 0.0%
Branches: 0 72 0.0%

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 bool 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 return true;
66 }
67
68 virtual void ReportRemoval(const PathString& path,
69 const catalog::DirectoryEntry& entry)
70 {
71 listener_->OnRemove(path.ToString(), entry);
72 }
73
74 virtual bool ReportModification(const PathString& path,
75 const catalog::DirectoryEntry& old_entry,
76 const catalog::DirectoryEntry& new_entry,
77 const XattrList& /*xattrs */,
78 const FileChunkList& /* chunks */)
79 {
80 listener_->OnModify(path.ToString(), old_entry, new_entry);
81 return true;
82 }
83 }; // class DiffForwarder
84
85 } // anonymous namespace
86
87 namespace publish {
88
89 void Repository::Diff(const std::string &from, const std::string &to,
90 DiffListener *diff_listener)
91 {
92 history::History::Tag from_tag = GetTag(from, *history_);
93 history::History::Tag to_tag = GetTag(to, *history_);
94 diff_listener->OnInit(from_tag, to_tag);
95
96 perf::Statistics stats_from;
97 catalog::SimpleCatalogManager *mgr_from = new catalog::SimpleCatalogManager(
98 from_tag.root_hash,
99 settings_.url(),
100 settings_.tmp_dir(),
101 download_mgr_,
102 &stats_from,
103 true /* manage_catalog_files */);
104 mgr_from->Init();
105
106 perf::Statistics stats_to;
107 catalog::SimpleCatalogManager *mgr_to = new catalog::SimpleCatalogManager(
108 to_tag.root_hash,
109 settings_.url(),
110 settings_.tmp_dir(),
111 download_mgr_,
112 &stats_to,
113 true /* manage_catalog_files */);
114 mgr_to->Init();
115
116 catalog::Counters counters_from = mgr_from->GetRootCatalog()->GetCounters();
117 catalog::Counters counters_to = mgr_to->GetRootCatalog()->GetCounters();
118 diff_listener->OnStats(catalog::Counters::Diff(counters_from, counters_to));
119
120 // DiffTool takes ownership of the catalog managers
121 DiffForwarder diff_forwarder(mgr_from, mgr_to, diff_listener);
122 if (!diff_forwarder.Init())
123 throw EPublish("cannot initialize difference engine");
124 diff_forwarder.Run(PathString());
125 }
126
127 } // namespace publish
128