GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/repository_abort.cc
Date: 2026-09-06 02:40:30
Exec Total Coverage
Lines: 0 39 0.0%
Branches: 0 82 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include <unistd.h>
7
8 #include <string>
9
10 #include "publish/except.h"
11 #include "publish/repository.h"
12 #include "publish/repository_util.h"
13 #include "publish/settings.h"
14 #include "util/logging.h"
15 #include "util/posix.h" // IWYU pragma: keep
16
17 namespace {
18
19 void TrySessionDrop(publish::Publisher::Session *session,
20 bool ignore_invalid_lease) {
21 try {
22 session->Drop();
23 } catch (const publish::EPublish &e) {
24 if (ignore_invalid_lease
25 && ((e.failure() == e.kFailLeaseBody)
26 || (e.failure() == e.kFailLeaseNoEntry))) {
27 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogWarn,
28 "force abort, continue despite error while trying to drop lease,"
29 " removing session token. Error: %s",
30 e.msg().c_str());
31 unlink(session->token_path().c_str());
32 unlink(session->api_version_path().c_str());
33 return;
34 }
35 throw e;
36 }
37 }
38
39 } // anonymous namespace
40
41 namespace publish {
42
43 void Publisher::WipeScratchArea() {
44 // TODO(jblomer): implement for enter shell etc.
45 if (managed_node_.get() == nullptr)
46 return;
47
48 managed_node_->ClearScratch();
49 }
50
51 void Publisher::Abort() {
52 const ServerLockFileGuard g(is_publishing_);
53
54 if (!in_transaction_.IsSet()) {
55 if (session_->has_lease()) {
56 LogCvmfs(kLogCvmfs, kLogSyslogWarn, "removing stale session token for %s",
57 settings_.fqrn().c_str());
58 TrySessionDrop(session_.get(), settings_.ignore_invalid_lease());
59 }
60 throw EPublish(
61 "Repository " + settings_.fqrn() + " is not in a transaction",
62 EPublish::kFailTransactionState);
63 }
64
65 TrySessionDrop(session_.get(), settings_.ignore_invalid_lease());
66
67 if (managed_node_.get() != nullptr) {
68 // We already checked for is_publishing and in_transaction. Normally, at
69 // this point we do want to repair the mount points of a repository
70 // in transaction
71 const EUnionMountRepairMode
72 repair_mode = settings_.transaction().spool_area().repair_mode();
73 if (repair_mode == kUnionMountRepairSafe) {
74 settings_.GetTransaction()->GetSpoolArea()->SetRepairMode(
75 kUnionMountRepairAlways);
76 }
77 const int rvi = managed_node_->Check(false /* is_quiet */);
78 settings_.GetTransaction()->GetSpoolArea()->SetRepairMode(repair_mode);
79 if (rvi != 0)
80 throw EPublish("publisher file system mount state is broken");
81
82 managed_node_->Unmount();
83 managed_node_->ClearScratch();
84 managed_node_->Mount();
85 }
86
87 in_transaction_.Clear();
88 }
89
90 } // namespace publish
91