GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/repository_util.h
Date: 2026-04-05 02:35:23
Exec Total Coverage
Lines: 0 18 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * Private utility functions for libcvmfs_server
5 */
6
7 #ifndef CVMFS_PUBLISH_REPOSITORY_UTIL_H_
8 #define CVMFS_PUBLISH_REPOSITORY_UTIL_H_
9
10 #include <string>
11
12 #include "crypto/hash.h"
13 #include "util/single_copy.h"
14
15 namespace publish {
16
17 class CheckoutMarker {
18 public:
19 CheckoutMarker(const std::string &t,
20 const std::string &b,
21 const shash::Any &h,
22 const std::string &p)
23 : tag_(t), branch_(b), hash_(h), previous_branch_(p) { }
24
25 static CheckoutMarker *CreateFrom(const std::string &path);
26 void SaveAs(const std::string &path) const;
27
28 std::string tag() const { return tag_; }
29 std::string branch() const { return branch_; }
30 shash::Any hash() const { return hash_; }
31 std::string previous_branch() const { return previous_branch_; }
32
33 private:
34 std::string tag_;
35 std::string branch_;
36 shash::Any hash_;
37 std::string previous_branch_;
38 };
39
40
41 /**
42 * A server lock file is a POSIX lock file used to obtain mutually
43 * exclusive access to the repository while conducting an operation
44 * that modifies the repository state.
45 *
46 * Since the lock is implemented using a POSIX lock file, the lock
47 * will automatically be released when the creating process exits.
48 */
49 class ServerLockFile {
50 public:
51 explicit ServerLockFile(const std::string &path) : path_(path), fd_(-1) { }
52
53 void Lock();
54 bool TryLock();
55 void Unlock();
56 void Touch();
57
58 const std::string &path() const { return path_; }
59
60 private:
61 std::string path_;
62 int fd_;
63 };
64
65 /**
66 * RAII try-lock owner for ServerLockFile
67 *
68 * TODO(mcb30): C++11 - replace by std::unique_lock<ServerLockFile>
69 * (with std::try_to_lock constructor)
70 */
71 class ServerLockFileCheck : SingleCopy {
72 public:
73 explicit ServerLockFileCheck(ServerLockFile &lock) : lock_(lock) {
74 owns_lock_ = lock_.TryLock();
75 }
76 ~ServerLockFileCheck() {
77 if (owns_lock_)
78 lock_.Unlock();
79 }
80
81 const bool owns_lock() const { return owns_lock_; }
82
83 private:
84 ServerLockFile &lock_;
85 bool owns_lock_;
86 };
87
88 /**
89 * RAII lock owner for ServerLockFile
90 *
91 * TODO(mcb30): C++11 - replace by std::lock_guard<ServerLockFile>
92 */
93 class ServerLockFileGuard : SingleCopy {
94 public:
95 explicit ServerLockFileGuard(ServerLockFile &lock) : lock_(lock) {
96 lock_.Lock();
97 }
98 ~ServerLockFileGuard() { lock_.Unlock(); }
99
100 private:
101 ServerLockFile &lock_;
102 };
103
104 /**
105 * A server flag file is a file used to indicate a single-bit state
106 * that extends beyond the lifetime of a process, such as the
107 * indication that a transaction is open.
108 */
109 class ServerFlagFile {
110 public:
111 explicit ServerFlagFile(const std::string &path) : path_(path) { }
112
113 void Set();
114 void Clear();
115 bool IsSet() const;
116
117 const std::string &path() const { return path_; }
118
119 private:
120 std::string path_;
121 };
122
123 /**
124 * Callout to cvmfs_suid_helper $verb $fqrn
125 */
126 void RunSuidHelper(const std::string &verb, const std::string &fqrn);
127
128
129 /**
130 * Replaces or creates $key=$value in the config file $path. Creates $path
131 * if necessary. If value is empty, the key is removed.
132 */
133 void SetInConfig(const std::string &path, const std::string &key,
134 const std::string &value);
135
136 std::string SendTalkCommand(const std::string &socket, const std::string &cmd);
137
138 } // namespace publish
139
140 #endif // CVMFS_PUBLISH_REPOSITORY_UTIL_H_
141