GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_commit.cc
Date: 2026-04-26 02:35:59
Exec Total Coverage
Lines: 0 38 0.0%
Branches: 0 96 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include "cmd_commit.h"
7
8 #include <errno.h>
9
10 #include <ctime>
11 #include <string>
12 #include <vector>
13
14 #include "publish/except.h"
15 #include "publish/repository.h"
16 #include "publish/settings.h"
17 #include "util/logging.h"
18 #include "util/posix.h"
19 #include "util/string.h"
20 #include "whitelist.h"
21
22 namespace publish {
23
24 int CmdCommit::Main(const Options &options) {
25 // Repository name and lease path are submitted as a single argument
26 // for historical reasons
27 std::string fqrn;
28
29 if (!options.plain_args().empty()) {
30 std::vector<std::string> tokens = SplitStringBounded(
31 2, options.plain_args()[0].value_str, '/');
32 fqrn = tokens[0];
33 }
34
35 SettingsBuilder builder;
36 const std::string session_dir = Env::GetEnterSessionDir();
37 builder.SetConfigPath(session_dir);
38
39 UniquePtr<SettingsPublisher> settings;
40 try {
41 settings = builder.CreateSettingsPublisher(fqrn, true /* needs_managed */);
42 } catch (const EPublish &e) {
43 if (e.failure() == EPublish::kFailRepositoryNotFound) {
44 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "CernVM-FS error: %s",
45 e.msg().c_str());
46 return 1;
47 }
48 throw;
49 }
50
51 if (!SwitchCredentials(settings->owner_uid(), settings->owner_gid(),
52 false /* temporarily */)) {
53 throw EPublish("No write permission to repository");
54 }
55
56 const FileSystemInfo fs_info = GetFileSystemInfo("/cvmfs");
57 if (fs_info.type == kFsTypeAutofs)
58 throw EPublish("Autofs on /cvmfs has to be disabled");
59
60 UniquePtr<Publisher> publisher;
61 try {
62 publisher = new Publisher(*settings);
63 if (publisher->whitelist()->IsExpired()) {
64 throw EPublish("Repository whitelist for $name is expired",
65 EPublish::kFailWhitelistExpired);
66 }
67 } catch (const EPublish &e) {
68 if (e.failure() == EPublish::kFailLayoutRevision
69 || e.failure() == EPublish::kFailWhitelistExpired) {
70 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "%s", e.msg().c_str());
71 return EINVAL;
72 }
73 }
74
75 const double whitelist_valid_s = difftime(publisher->whitelist()->expires(),
76 time(NULL));
77 if (whitelist_valid_s < (12 * 60 * 60)) {
78 LogCvmfs(
79 kLogCvmfs, kLogStdout,
80 "Warning: Repository whitelist stays valid for less than 12 hours!");
81 }
82
83 publisher->Sync();
84 SafeWriteToFile("commit", session_dir + "/shellaction.marker", 0600);
85 LogCvmfs(kLogCvmfs, kLogStdout, "Changes saved!");
86 publisher->ExitShell();
87
88 return 0;
89 }
90
91 } // namespace publish
92