GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_tag.cc
Date: 2026-08-23 02:40:52
Exec Total Coverage
Lines: 0 49 0.0%
Branches: 0 114 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include "cmd_tag.h"
7
8 #include <errno.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "history.h"
15 #include "publish/except.h"
16 #include "publish/repository.h"
17 #include "publish/settings.h"
18 #include "upload_spooler_definition.h"
19 #include "util/logging.h"
20 #include "util/posix.h"
21 #include "util/string.h"
22 #include "whitelist.h"
23
24 namespace publish {
25
26 int CmdTag::Main(const Options &options) {
27 const std::string fqrn = options.plain_args()[0].value_str;
28
29 const bool has_add = options.Has("add");
30 const bool has_remove = options.Has("remove");
31 if (!has_add && !has_remove)
32 throw EPublish("neither tags to add (-a) nor to remove (-d) given",
33 EPublish::kFailInvocation);
34
35 SettingsBuilder builder;
36 std::unique_ptr<SettingsPublisher> settings;
37 try {
38 settings.reset(
39 builder.CreateSettingsPublisher(fqrn, true /* needs_managed */));
40 } catch (const EPublish &e) {
41 if (e.failure() == EPublish::kFailRepositoryNotFound) {
42 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "CernVM-FS error: %s",
43 e.msg().c_str());
44 return 1;
45 }
46 throw;
47 }
48
49 if (settings->storage().type() != upload::SpoolerDefinition::Gateway) {
50 throw EPublish("'cvmfs_publish tag' only supports gateway repositories",
51 EPublish::kFailInvocation);
52 }
53
54 if (!SwitchCredentials(settings->owner_uid(), settings->owner_gid(),
55 false /* temporarily */)) {
56 throw EPublish("No write permission to repository",
57 EPublish::kFailPermission);
58 }
59
60 std::unique_ptr<Publisher> publisher;
61 try {
62 publisher.reset(new Publisher(*settings));
63 if (publisher->whitelist()->IsExpired()) {
64 throw EPublish("Repository whitelist for " + fqrn + " is expired",
65 EPublish::kFailWhitelistExpired);
66 }
67 } catch (const EPublish &e) {
68 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "%s", e.msg().c_str());
69 if (e.failure() == EPublish::kFailLayoutRevision
70 || e.failure() == EPublish::kFailWhitelistExpired) {
71 return EINVAL;
72 }
73 return EIO;
74 }
75
76 std::vector<history::History::Tag> add_tags;
77 if (has_add) {
78 history::History::Tag tag;
79 tag.name = options.GetString("add");
80 if (options.Has("description"))
81 tag.description = options.GetString("description");
82 add_tags.push_back(tag);
83 }
84
85 std::vector<std::string> rm_tags;
86 if (has_remove)
87 rm_tags = SplitString(options.GetString("remove"), ' ');
88
89 try {
90 publisher->EditTags(add_tags, rm_tags);
91 } catch (const EPublish &e) {
92 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "CernVM-FS tag error: %s",
93 e.msg().c_str());
94 if (e.failure() == EPublish::kFailLeaseBusy)
95 return EBUSY;
96 return EIO;
97 }
98
99 return 0;
100 }
101
102 } // namespace publish
103