From 40947cabcd2d023822a7c27db9636aa764972271 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 26 Jul 2023 14:39:21 +0900 Subject: [PATCH] shared: Replace do_copy_force() with syscommon_file_copy() Change-Id: I4522ca9f1f9a2aebdc16b106e8d0536bca6cae9b Signed-off-by: Youngjae Cho --- src/display/lock-detector.c | 5 +++-- src/shared/common.c | 44 -------------------------------------------- src/shared/common.h | 1 - 3 files changed, 3 insertions(+), 47 deletions(-) diff --git a/src/display/lock-detector.c b/src/display/lock-detector.c index ca8fc52..aef6969 100644 --- a/src/display/lock-detector.c +++ b/src/display/lock-detector.c @@ -31,6 +31,7 @@ #include #include #include +#include #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); diff --git a/src/shared/common.c b/src/shared/common.c index fc4846e..d8cac72 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -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; diff --git a/src/shared/common.h b/src/shared/common.h index 6c80016..6a2517c 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -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 -- 2.7.4