Merge move_dump_dir() and move_info_file() 27/188127/5
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 31 Aug 2018 10:44:13 +0000 (12:44 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 5 Sep 2018 07:31:34 +0000 (09:31 +0200)
Change-Id: I246bf743eefb199577bd00d6b3fd0defa6948eff

src/crash-manager/crash-manager.c

index cf6525e..3aa16d6 100644 (file)
@@ -1133,43 +1133,23 @@ static void compress(struct crash_info *cinfo)
                _E("Failed to delete temp directory");
 }
 
-static void move_dump_dir(const struct crash_info *cinfo)
+static void move_dump_data(const char *from_path, const struct crash_info *cinfo)
 {
        int lock_fd;
 
        if ((lock_fd = lock_dumpdir()) < 0)
                return;
-       if (!rename(cinfo->pfx, cinfo->result_path))
+       if (!rename(from_path, cinfo->result_path))
                clean_dump();
        else
                _E("Failed to move %s to %s",
-                               cinfo->pfx, cinfo->result_path);
+                               from_path, cinfo->result_path);
        unlock_dumpdir(lock_fd);
 
        if (remove_dir(cinfo->temp_dir, 1) < 0)
                _E("Failed to delete temp directory");
 }
 
-static void move_info_file(struct crash_info *cinfo)
-{
-       int lock_fd;
-
-       if ((lock_fd = lock_dumpdir()) < 0)
-               return;
-
-       snprintf(cinfo->result_path, sizeof(cinfo->result_path), "%s/%s.info",
-                        crash_crash_path, cinfo->name);
-       if (!rename(cinfo->info_path, cinfo->result_path))
-               clean_dump();
-       else
-               _E("Failed to move %s to %s",
-                  cinfo->info_path, cinfo->result_path);
-
-       unlock_dumpdir(lock_fd);
-       if (remove_dir(cinfo->temp_dir, 1) < 0)
-               _E("Failed to delete temp directory");
-}
-
 static int wait_for_opt(unsigned int timeout)
 {
        unsigned int count = 0;
@@ -1262,9 +1242,11 @@ int main(int argc, char *argv[])
                if (allow_zip)
                        compress(&cinfo);
                else
-                       move_dump_dir(&cinfo);
+                       move_dump_data(cinfo.pfx, &cinfo);
        } else {
-               move_info_file(&cinfo);
+               snprintf(cinfo.result_path, sizeof(cinfo.result_path), "%s/%s.info",
+                                crash_crash_path, cinfo.name);
+               move_dump_data(cinfo.info_path, &cinfo);
        }
        /* launch crash-popup only if the .debugmode file is exist*/
        if (debug_mode)