25 if (!repo_and_path.empty()) {
26 std::vector<std::string> tokens =
SplitString(repo_and_path,
'/');
38 const std::string session_dir = Env::GetEnterSessionDir();
40 if (!session_dir.empty()) {
65 throw EPublish(
"No write permission to repository",
70 settings->transaction().spool_area().union_mnt() +
"/",
73 "Current working directory is in %s. Please release, "
74 "e.g. by 'cd $HOME'.",
75 settings->transaction().spool_area().union_mnt().c_str());
79 if (!options.
Has(
"force")) {
81 "You are about to DISCARD ALL CHANGES OF THE CURRENT TRANSACTION "
82 "for %s! Are you sure (y/N)? ",
83 settings->fqrn().c_str());
84 char answer[] = {0, 0, 0};
85 char *rv_charp = fgets(answer, 3, stdin);
86 if (rv_charp && (answer[0] !=
'Y') && (answer[0] !=
'y'))
92 settings->SetIgnoreInvalidLease(
true);
95 std::vector<LsofEntry> lsof_entries =
Lsof(
96 settings->transaction().spool_area().union_mnt());
97 if (!lsof_entries.empty()) {
98 if (options.
Has(
"force")) {
100 "WARNING: Open file descriptors on %s (possible race!)"
101 "\nThe following lsof report might show the culprit:\n",
102 settings->transaction().spool_area().union_mnt().c_str());
105 "\nWARNING! There are open read-only file descriptors in %s\n"
106 " --> This is potentially harmful and might cause problems "
108 " We can anyway perform the requested operation, but this "
110 " break other processes with open file descriptors on %s!\n"
112 " The following lsof report might show the processes with "
113 "open file handles\n",
114 settings->transaction().spool_area().union_mnt().c_str(),
115 settings->transaction().spool_area().union_mnt().c_str());
118 for (
unsigned i = 0; i < lsof_entries.size(); ++i) {
119 std::string owner_name;
122 lsof_entries[i].executable.c_str(), lsof_entries[i].pid,
123 owner_name.c_str(), lsof_entries[i].path.c_str());
126 if (!options.
Has(
"force")) {
128 "\n Do you want to proceed anyway? (y/N) ");
129 char answer[] = {0, 0, 0};
130 char *rv_charp = fgets(answer, 3, stdin);
131 if (rv_charp && (answer[0] !=
'Y') && (answer[0] !=
'y'))
140 settings->fqrn().c_str());
145 "abort hook failed, not aborting");
166 if (settings->transaction().in_enter_session()) {
168 "Discarding changes and closing current transaction...");
170 publisher->ExitShell();
std::string StripTrailingPath(const std::string &repo_and_path)
SettingsPublisher * CreateSettingsPublisher(const std::string &ident, bool needs_managed=false)
int CallServerHook(const std::string &func, const std::string &fqrn, const std::string &path_hooks="/etc/cvmfs/cvmfs_server_hooks.sh")
bool Has(const std::string &key) const
bool GetUserNameOf(uid_t uid, std::string *username)
const SettingsPublisher & settings() const
bool SafeWriteToFile(const std::string &content, const std::string &path, int mode)
void SetConfigPath(const std::string &config_path)
const std::vector< Argument > & plain_args() const
vector< string > SplitString(const string &str, char delim)
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
EFailures failure() const
bool SwitchCredentials(const uid_t uid, const gid_t gid, const bool temporarily)
std::vector< LsofEntry > Lsof(const std::string &path)
Publisher(const SettingsPublisher &settings, const bool exists=true)
std::string GetCurrentWorkingDirectory()
virtual int Main(const Options &options)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)