GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/repository_abort.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 0 37 0.0%
Branches: 0 80 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 "publish/repository.h"
7
8 #include <unistd.h>
9
10 #include <string>
11
12 #include "publish/except.h"
13 #include "publish/repository_util.h"
14 #include "publish/settings.h"
15 #include "util/logging.h"
16 #include "util/posix.h"
17
18 namespace {
19
20 void TrySessionDrop(publish::Publisher::Session *session,
21 bool ignore_invalid_lease)
22 {
23 try {
24 session->Drop();
25 } catch (const publish::EPublish &e) {
26 if (ignore_invalid_lease &&
27 ((e.failure() == e.kFailLeaseBody) ||
28 (e.failure() == e.kFailLeaseNoEntry)))
29 {
30 LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogWarn,
31 "force abort, continue despite error while trying to drop lease,"
32 " removing session token. Error: %s", e.msg().c_str());
33 unlink(session->token_path().c_str());
34 return;
35 }
36 throw e;
37 }
38 }
39
40 } // anonymous namespace
41
42 namespace publish {
43
44 void Publisher::WipeScratchArea() {
45 // TODO(jblomer): implement for enter shell etc.
46 if (!managed_node_.IsValid())
47 return;
48
49 managed_node_->ClearScratch();
50 }
51
52 void Publisher::Abort() {
53 ServerLockFileGuard g(is_publishing_);
54
55 if (!in_transaction_.IsSet()) {
56 if (session_->has_lease()) {
57 LogCvmfs(kLogCvmfs, kLogSyslogWarn, "removing stale session token for %s",
58 settings_.fqrn().c_str());
59 TrySessionDrop(session_.weak_ref(), settings_.ignore_invalid_lease());
60 }
61 throw EPublish(
62 "Repository " + settings_.fqrn() + " is not in a transaction",
63 EPublish::kFailTransactionState);
64 }
65
66 TrySessionDrop(session_.weak_ref(), settings_.ignore_invalid_lease());
67
68 if (managed_node_.IsValid()) {
69 // We already checked for is_publishing and in_transaction. Normally, at
70 // this point we do want to repair the mount points of a repository
71 // in transaction
72 EUnionMountRepairMode repair_mode =
73 settings_.transaction().spool_area().repair_mode();
74 if (repair_mode == kUnionMountRepairSafe) {
75 settings_.GetTransaction()->GetSpoolArea()->SetRepairMode(
76 kUnionMountRepairAlways);
77 }
78 int rvi = managed_node_->Check(false /* is_quiet */);
79 settings_.GetTransaction()->GetSpoolArea()->SetRepairMode(repair_mode);
80 if (rvi != 0) 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