GCC Code Coverage Report


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