Supress build warnings
[platform/core/appfw/wgt-backend.git] / src / unit_tests / smoke_utils.cc
index 2ef8402..3721b48 100644 (file)
@@ -149,7 +149,7 @@ bool DeleteUser(const char *user_name, bool rem_home_dir) {
 
 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);
@@ -170,7 +170,7 @@ bool DeleteTestUser(const char *user_name) {
   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;
@@ -729,7 +729,21 @@ ci::AppInstaller::Result Recover(const bf::path& recovery_file,
   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;
@@ -739,28 +753,42 @@ void BackupPath(const bf::path& path) {
                << " (" << 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() {