5 #include "cvmfs_config.h"
57 const std::string scratch_dir =
58 publisher_->settings_.transaction().spool_area().scratch_dir();
59 const std::string scratch_wastebin =
60 publisher_->settings_.transaction().spool_area().scratch_wastebin();
61 const std::string tmp_dir =
62 publisher_->settings_.transaction().spool_area().tmp_dir();
64 std::string waste_dir =
CreateTempDir(scratch_wastebin +
"/waste");
65 if (waste_dir.empty())
throw EPublish(
"cannot create wastebin directory");
66 int rvi = rename(scratch_dir.c_str(), (waste_dir +
"/delete-me").c_str());
67 if (rvi != 0)
throw EPublish(
"cannot move scratch directory to wastebin");
73 std::vector<mode_t> modes;
74 std::vector<std::string> names;
76 for (
unsigned i = 0; i < names.size(); ++i) {
77 if (
HasPrefix(names[i],
"receiver.",
false ))
80 unlink((tmp_dir +
"/" + names[i]).c_str());
86 ServerLockFileCheck publish_check(
publisher_->is_publishing_);
87 const std::string rdonly_mnt =
88 publisher_->settings_.transaction().spool_area().readonly_mnt();
89 const std::string union_mnt =
90 publisher_->settings_.transaction().spool_area().union_mnt();
91 const std::string fqrn =
publisher_->settings_.fqrn();
93 publisher_->settings_.transaction().spool_area().repair_mode();
99 publisher_->settings_.transaction().spool_area().checkout_marker()));
100 if (marker.IsValid())
101 expected_hash = marker->hash();
104 result |= kFailRdOnlyBroken;
106 const std::string root_hash_xattr =
"user.root_hash";
107 std::string root_hash_str;
113 if (expected_hash != root_hash) {
114 if (marker.IsValid()) {
115 result |= kFailRdOnlyWrongRevision;
117 result |= kFailRdOnlyOutdated;
121 if (errno == ENOTCONN) {
123 result |= kFailRdOnlyBroken;
125 throw EPublish(
"cannot retrieve root hash from read-only mount point");
133 result |= kFailUnionBroken;
137 result |= kFailUnionLocked;
139 result |= kFailUnionWritable;
150 if (result & kFailRdOnlyBroken) {
154 if (result & kFailRdOnlyOutdated) {
156 "%s is not based on the newest published revision", fqrn.c_str());
158 if (result & kFailRdOnlyWrongRevision) {
160 "%s is not based on the checked out revision", fqrn.c_str());
162 if (result & kFailUnionBroken) {
166 if (result & kFailUnionWritable) {
168 "%s is not in a transaction but %s is mounted read/write",
169 fqrn.c_str(), union_mnt.c_str());
171 if (result & kFailUnionLocked) {
173 "%s is in a transaction but %s is not mounted read/write",
174 fqrn.c_str(), union_mnt.c_str());
179 switch (repair_mode) {
185 if (!publish_check.owns_lock()) {
187 "WARNING: The repository %s is currently publishing and should not\n"
188 "be touched. If you are absolutely sure, that this is _not_ the "
189 "case,\nplease run the following command and retry:\n\n"
191 fqrn.c_str(),
publisher_->is_publishing_.path().c_str());
197 "Repository %s is in a transaction and cannot be repaired.\n"
198 "--> Run `cvmfs_server abort $name` to revert and repair.",
209 fqrn.c_str(), result);
226 if ((result & kFailRdOnlyOutdated) || (result & kFailRdOnlyWrongRevision)) {
227 if ((result & kFailUnionBroken) == 0) {
229 result |= kFailUnionBroken;
232 if ((result & kFailRdOnlyBroken) == 0) {
234 result |= kFailRdOnlyBroken;
238 result &= ~kFailRdOnlyOutdated;
239 result &= ~kFailRdOnlyWrongRevision;
242 if (result & kFailRdOnlyBroken) {
243 if ((result & kFailUnionBroken) == 0) {
245 result |= kFailUnionBroken;
248 result &= ~kFailRdOnlyBroken;
251 if (result & kFailUnionBroken) {
255 result |= kFailUnionLocked;
257 result &= ~kFailUnionBroken;
258 result &= ~kFailUnionWritable;
261 if (result & kFailUnionLocked) {
263 result &= ~kFailUnionLocked;
266 if (result & kFailUnionWritable) {
268 result &= ~kFailUnionWritable;
279 std::string mountpoint;
280 std::string info_msg;
281 std::string suid_helper_verb;
284 mountpoint =
publisher_->settings_.transaction().spool_area().union_mnt();
285 info_msg =
"Trying to unmount " + mountpoint;
286 suid_helper_verb =
"rw_umount";
289 mountpoint =
publisher_->settings_.transaction().spool_area().union_mnt();
290 info_msg =
"Trying to lazily unmount " + mountpoint;
291 suid_helper_verb =
"rw_lazy_umount";
295 publisher_->settings_.transaction().spool_area().readonly_mnt();
296 info_msg =
"Trying to unmount " + mountpoint;
297 suid_helper_verb =
"rdonly_umount";
301 publisher_->settings_.transaction().spool_area().readonly_mnt();
302 info_msg =
"Trying to forcefully stop " + mountpoint;
303 suid_helper_verb =
"kill_cvmfs";
307 publisher_->settings_.transaction().spool_area().readonly_mnt();
308 info_msg =
"Trying to lazily unmount " + mountpoint;
309 suid_helper_verb =
"rdonly_lazy_umount";
312 mountpoint =
publisher_->settings_.transaction().spool_area().union_mnt();
313 info_msg =
"Trying to mount " + mountpoint;
314 suid_helper_verb =
"rw_mount";
318 publisher_->settings_.transaction().spool_area().readonly_mnt();
319 info_msg =
"Trying to mount " + mountpoint;
320 suid_helper_verb =
"rdonly_mount";
323 mountpoint =
publisher_->settings_.transaction().spool_area().union_mnt();
324 info_msg =
"Trying to remount " + mountpoint +
" read/write";
325 suid_helper_verb =
"open";
329 publisher_->settings_.transaction().spool_area().union_mnt();
330 info_msg =
"Trying to remount " + mountpoint +
" read-only";
331 suid_helper_verb =
"lock";
335 publisher_->settings_.transaction().spool_area().scratch_dir();
336 info_msg =
"Trying to wipe out " + mountpoint +
" (async cleanup)";
337 suid_helper_verb =
"clear_scratch_async";
340 throw EPublish(
"internal error: unknown mountpoint alteration");
352 if (log_level & kLogStdout)
357 throw EPublish(info_msg +
"... fail");
363 const std::string config_path =
364 publisher_->settings_.transaction().spool_area().client_lconfig();
static void Mount(const string &path)
std::string ToString(const bool with_suffix=false) const
void AlterMountpoint(EMountpointAlterations how, int log_level)
const int kDefaultDirMode
FileSystemInfo GetFileSystemInfo(const std::string &path)
const char kSuffixCatalog
void SetInConfig(const std::string &path, const std::string &key, const std::string &value)
std::string CreateTempDir(const std::string &path_prefix)
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
void RunSuidHelper(const std::string &verb, const std::string &fqrn)
bool ListDirectory(const std::string &directory, std::vector< std::string > *names, std::vector< mode_t > *modes)
Any MkFromHexPtr(const HexPtr hex, const char suffix)
void SetRootHash(const shash::Any &hash)
bool IsMountPoint(const std::string &path)
static CheckoutMarker * CreateFrom(const std::string &path)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)