GCC Code Coverage Report


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