GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_commit.cc
Date: 2024-04-21 02:33:16
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 #include "cvmfs_config.h"
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 =
32 SplitStringBounded(2, options.plain_args()[0].value_str, '/');
33 fqrn = tokens[0];
34 }
35
36 SettingsBuilder builder;
37 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 {
55 throw EPublish("No write permission to repository");
56 }
57
58 FileSystemInfo fs_info = GetFileSystemInfo("/cvmfs");
59 if (fs_info.type == kFsTypeAutofs)
60 throw EPublish("Autofs on /cvmfs has to be disabled");
61
62 UniquePtr<Publisher> publisher;
63 try {
64 publisher = new Publisher(*settings);
65 if (publisher->whitelist()->IsExpired()) {
66 throw EPublish("Repository whitelist for $name is expired",
67 EPublish::kFailWhitelistExpired);
68 }
69 } catch (const EPublish &e) {
70 if (e.failure() == EPublish::kFailLayoutRevision ||
71 e.failure() == EPublish::kFailWhitelistExpired)
72 {
73 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, "%s", e.msg().c_str());
74 return EINVAL;
75 }
76 }
77
78 double whitelist_valid_s =
79 difftime(publisher->whitelist()->expires(), time(NULL));
80 if (whitelist_valid_s < (12 * 60 * 60)) {
81 LogCvmfs(kLogCvmfs, kLogStdout,
82 "Warning: Repository whitelist stays valid for less than 12 hours!");
83 }
84
85 publisher->Sync();
86 SafeWriteToFile("commit", session_dir + "/shellaction.marker", 0600);
87 LogCvmfs(kLogCvmfs, kLogStdout, "Changes saved!");
88 publisher->ExitShell();
89
90 return 0;
91 }
92
93 } // namespace publish
94