bool AddTestUser(const char *user_name) {
std::cout << "Adding test user: " << user_name << std::endl;
- bool ret = AddUser(user_name);
+ AddUser(user_name);
if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
kTestUserId = *uid;
kTestUserIdStr = std::to_string(kTestUserId);
uid_t test_uid;
if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name))
test_uid = *uid;
- bool ret = DeleteUser(user_name, true);
+ DeleteUser(user_name, true);
if (!ci::GetUidByUserName(user_name)) {
std::cout << "User deleted properly: user_name=" << user_name
<< " uid=" << test_uid << std::endl;
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
-void BackupPath(const bf::path& path) {
+namespace {
+
+boost::filesystem::path GetTrashPath(const boost::filesystem::path& path) {
+ return path.string() + ".trash";
+}
+
+}
+
+bool BackupPath(const bf::path& path) {
+ bf::path trash_path = GetTrashPath(path);
+ if (bf::exists(trash_path)) {
+ LOG(ERROR) << trash_path << " exists. Please remove "
+ << trash_path << " manually!";
+ return false;
+ }
bf::path backup_path = path.string() + ".bck";
std::cout << "Backup path: " << path << " to " << backup_path << std::endl;
bs::error_code error;
<< " (" << error.message() << ")";
if (bf::exists(path)) {
bf::rename(path, backup_path, error);
- if (error)
+ if (error) {
LOG(ERROR) << "Failed to setup test environment. Does some previous"
<< " test crashed? Path: "
<< backup_path << " should not exist.";
+ return false;
+ }
assert(!error);
}
+ return true;
}
-void RestorePath(const bf::path& path) {
+bool RestorePath(const bf::path& path) {
bf::path backup_path = path.string() + ".bck";
std::cout << "Restore path: " << path << " from " << backup_path << std::endl;
bs::error_code error;
bf::remove_all(path, error);
- if (error)
- LOG(ERROR) << "Remove failed: " << path
- << " (" << error.message() << ")";
+ if (error) {
+ bf::path trash_path = GetTrashPath(path);
+ LOG(ERROR) << "Remove failed: " << path << " (" << error.message() << ")";
+ std::cout << "Moving " << path << " to " << trash_path << std::endl;
+ bf::rename(path, trash_path, error);
+ if (error)
+ LOG(ERROR) << "Failed to move " << path << " to " << trash_path
+ << " (" << error.message() << ")";
+ else
+ LOG(ERROR) << trash_path << " should be removed manually!";
+ }
if (bf::exists(backup_path)) {
bf::rename(backup_path, path, error);
- if (error)
+ if (error) {
LOG(ERROR) << "Failed to restore backup path: " << backup_path
<< " (" << error.message() << ")";
+ return false;
+ }
}
+ return true;
}
std::vector<bf::path> SetupBackupDirectories() {