From 252a64924fab5d53a6ee5d3ba8f3dbc497266c0a Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 14 Dec 2024 08:46:44 +0800 Subject: [PATCH] `cp -f` if not GNU `cp` [GitHub #152] --- src/framework/core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/framework/core.c b/src/framework/core.c index 3cf3d9f..2a60016 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -9,7 +9,7 @@ * | Yangmoooo * | * Created On : <2023-08-29> - * Last Modified : <2024-12-10> + * Last Modified : <2024-12-14> * * chsrc framework * ------------------------------------------------------------*/ @@ -1283,12 +1283,22 @@ chsrc_backup (const char *path) } else if (xy_on_windows) { - // /Y 表示覆盖 + /* /Y 表示覆盖 */ cmd = xy_strjoin (5, "copy /Y ", path, " ", path, ".bak" ); } else { - cmd = xy_strjoin (5, "cp ", path, " ", path, ".bak --backup='t'"); + char *ver = xy_run (xy_str_to_quietcmd ("cp --version"), 1, NULL); + /* cp (GNU coreutils) 9.4 */ + if (strstr (ver, "GNU coreutils")) + { + cmd = xy_strjoin (5, "cp ", path, " ", path, ".bak --backup='t'"); + } + else + { + /* 非 GNU 的 cp 可能不支持 --backup ,如 busybox cp */ + cmd = xy_strjoin (5, "cp -f ", path, " ", path, ".bak"); + } } chsrc_run_as_a_service (cmd);