CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
repository_abort.cc
Go to the documentation of this file.
1 
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"
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  {
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 
45  // TODO(jblomer): implement for enter shell etc.
46  if (!managed_node_.IsValid())
47  return;
48 
49  managed_node_->ClearScratch();
50 }
51 
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",
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(
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 
88 }
89 
90 } // namespace publish
const SettingsRepository settings_
Definition: repository.h:137
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:381
Session * session() const
Definition: repository.h:320
EUnionMountRepairMode
Definition: settings.h:64
std::string msg() const
Definition: except.h:46
void TrySessionDrop(publish::Publisher::Session *session, bool ignore_invalid_lease)
void Abort()
void WipeScratchArea()
ServerLockFile is_publishing_
Definition: repository.h:371
UniquePtr< Session > session_
Definition: repository.h:380
EFailures failure() const
Definition: except.h:45
ServerFlagFile in_transaction_
Definition: repository.h:370
std::string fqrn() const
Definition: settings.h:373
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528