| 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" |
| 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 |
|
✗ |
return; |
| 33 |
|
|
} |
| 34 |
|
✗ |
throw e; |
| 35 |
|
|
} |
| 36 |
|
|
} |
| 37 |
|
|
|
| 38 |
|
|
} // anonymous namespace |
| 39 |
|
|
|
| 40 |
|
|
namespace publish { |
| 41 |
|
|
|
| 42 |
|
✗ |
void Publisher::WipeScratchArea() { |
| 43 |
|
|
// TODO(jblomer): implement for enter shell etc. |
| 44 |
|
✗ |
if (!managed_node_.IsValid()) |
| 45 |
|
✗ |
return; |
| 46 |
|
|
|
| 47 |
|
✗ |
managed_node_->ClearScratch(); |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
✗ |
void Publisher::Abort() { |
| 51 |
|
✗ |
const ServerLockFileGuard g(is_publishing_); |
| 52 |
|
|
|
| 53 |
|
✗ |
if (!in_transaction_.IsSet()) { |
| 54 |
|
✗ |
if (session_->has_lease()) { |
| 55 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogSyslogWarn, "removing stale session token for %s", |
| 56 |
|
✗ |
settings_.fqrn().c_str()); |
| 57 |
|
✗ |
TrySessionDrop(session_.weak_ref(), settings_.ignore_invalid_lease()); |
| 58 |
|
|
} |
| 59 |
|
✗ |
throw EPublish( |
| 60 |
|
✗ |
"Repository " + settings_.fqrn() + " is not in a transaction", |
| 61 |
|
✗ |
EPublish::kFailTransactionState); |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
✗ |
TrySessionDrop(session_.weak_ref(), settings_.ignore_invalid_lease()); |
| 65 |
|
|
|
| 66 |
|
✗ |
if (managed_node_.IsValid()) { |
| 67 |
|
|
// We already checked for is_publishing and in_transaction. Normally, at |
| 68 |
|
|
// this point we do want to repair the mount points of a repository |
| 69 |
|
|
// in transaction |
| 70 |
|
|
const EUnionMountRepairMode |
| 71 |
|
✗ |
repair_mode = settings_.transaction().spool_area().repair_mode(); |
| 72 |
|
✗ |
if (repair_mode == kUnionMountRepairSafe) { |
| 73 |
|
✗ |
settings_.GetTransaction()->GetSpoolArea()->SetRepairMode( |
| 74 |
|
|
kUnionMountRepairAlways); |
| 75 |
|
|
} |
| 76 |
|
✗ |
const int rvi = managed_node_->Check(false /* is_quiet */); |
| 77 |
|
✗ |
settings_.GetTransaction()->GetSpoolArea()->SetRepairMode(repair_mode); |
| 78 |
|
✗ |
if (rvi != 0) |
| 79 |
|
✗ |
throw EPublish("publisher file system mount state is broken"); |
| 80 |
|
|
|
| 81 |
|
✗ |
managed_node_->Unmount(); |
| 82 |
|
✗ |
managed_node_->ClearScratch(); |
| 83 |
|
✗ |
managed_node_->Mount(); |
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
|
✗ |
in_transaction_.Clear(); |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
} // namespace publish |
| 90 |
|
|
|