Skip to content
Snippets Groups Projects
Commit ecfe9a68 authored by Steven Murray's avatar Steven Murray
Browse files

cta-immutable-file-test now prompts user before carrying out its destructive test

parent 6770c3a6
No related branches found
No related tags found
No related merge requests found
......@@ -84,6 +84,13 @@ int ImmutableFileTest::exceptionThrowingMain(const int argc, char *const *const
return 0;
}
if(userConfirmsDestroyFile(cmdLine.fileUrl.GetURL())) {
m_out << "Starting destructive test on file " << cmdLine.fileUrl.GetURL() << std::endl;
} else {
m_out << "Aborting" << std::endl;
return 0;
}
if(cmdLine.fileUrl.IsLocalFile()) {
exception::Exception ex;
ex.getMessage() << cmdLine.fileUrl.GetURL() << " is local";
......@@ -117,6 +124,23 @@ int ImmutableFileTest::exceptionThrowingMain(const int argc, char *const *const
return 0;
}
//------------------------------------------------------------------------------
// userConfirmsDestroyFile
//------------------------------------------------------------------------------
bool ImmutableFileTest::userConfirmsDestroyFile(const std::string &fileUrl) const {
m_out << "WARNING" << std::endl;
m_out << "You are about to destroy file " << fileUrl << std::endl;
m_out << "Are you sure you want to continue?" << std::endl;
std::string userResponse;
while(userResponse != "yes" && userResponse != "no") {
m_out << "Please type either \"yes\" or \"no\" > ";
std::getline(m_in, userResponse);
}
return userResponse == "yes";
}
//------------------------------------------------------------------------------
// fileExists
//------------------------------------------------------------------------------
......
......@@ -74,6 +74,14 @@ private:
*/
int exceptionThrowingMain(const int argc, char *const *const argv);
/**
* Asks the user to confirm that they want to destroy the specified file.
*
* @param fileUrl The URL of the file.
* @return True if the user confirmed.
*/
bool userConfirmsDestroyFile(const std::string &fileUrl) const;
/**
* @return True if the specified file exists
* @param url The XRootD URL of the file to be tested.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment