GCC Code Coverage Report


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