shared: Replace do_copy_force() with syscommon_file_copy() 60/296360/1
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 26 Jul 2023 05:39:21 +0000 (14:39 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 26 Jul 2023 05:39:21 +0000 (14:39 +0900)
Change-Id: I4522ca9f1f9a2aebdc16b106e8d0536bca6cae9b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/display/lock-detector.c
src/shared/common.c
src/shared/common.h

index ca8fc52..aef6969 100644 (file)
@@ -31,6 +31,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <libsyscommon/list.h>
+#include <libsyscommon/file.h>
 
 #include "core.h"
 #include "display-misc.h"
@@ -335,7 +336,7 @@ int pm_save_logdump(void)
        int ret;
 
        cleanup_pmlock_statistics();
-       ret = do_copy_force(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_FILE);
+       ret = syscommon_file_copy(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_FILE, true);
        if (ret < 0)
                _W("Can not move(%d)", ret);
 
@@ -349,7 +350,7 @@ static int pmlock_detector_poweroff_cb(void *data)
        int ret;
 
        cleanup_pmlock_statistics();
-       ret = do_copy_force(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_GHOST_PATH);
+       ret = syscommon_file_copy(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_GHOST_PATH, true);
        if (ret < 0)
                _W("Can not move(%d)", ret);
 
index fc4846e..d8cac72 100644 (file)
@@ -81,50 +81,6 @@ int do_mkdir(const char *path, mode_t mode)
        return 0;
 }
 
-static int do_copy_internal(const char *src, const char *dst, mode_t mode, bool force)
-{
-       _cleanup_close_ int rfd = -1, wfd = -1;
-       char buf[1024];
-       ssize_t red;
-       int r;
-
-       assert(src);
-       assert(dst);
-
-       if (!force) {
-               r = access(dst, F_OK);
-               if (r == 0)
-                       return -EALREADY;
-               else if (errno != ENOENT)
-                       return -errno;
-       }
-
-       wfd = open(dst, O_CREAT | O_WRONLY | O_TRUNC, mode);
-       if (wfd < 0)
-               return -errno;
-
-       rfd = open(src, O_RDONLY);
-       if (rfd < 0)
-               return -errno;
-
-       while ((red = read(rfd, buf, 1024)) > 0)
-               if (write(wfd, buf, red) != red)
-                       return -errno;
-
-       if (red < 0)
-               return -errno;
-
-       return 0;
-}
-
-int do_copy_force(const char *src, const char *dst)
-{
-       assert(src);
-       assert(dst);
-
-       return do_copy_internal(src, dst, 0644, true);
-}
-
 int get_command(pid_t pid, char *comm, size_t len)
 {
        FILE *fp;
index 6c80016..6a2517c 100644 (file)
@@ -198,7 +198,6 @@ static inline void __cleanup_fclose_func(FILE **f) {
 
 int get_systemd_reboot_param(char *buf, unsigned bufsize);
 int do_mkdir(const char *path, mode_t mode);
-int do_copy_force(const char *src, const char *dst);
 void watchdog_notify(void);
 #ifdef __cplusplus