summaryrefslogtreecommitdiff
path: root/src/shared/edit-util.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-04-07 01:41:24 +0800
committerMike Yuan <me@yhndnzj.com>2023-04-07 16:13:00 +0800
commitbc6c7a58c25f9e974996d43473fbfb1273d746c0 (patch)
tree2646bf79a8f04707d9d358e858b2a4eb2994c428 /src/shared/edit-util.c
parent54ad6aa164042a7e4c49abf59ad1d728c1bb6d0b (diff)
downloadsystemd-bc6c7a58c25f9e974996d43473fbfb1273d746c0.tar.gz
edit-util: introduce overwrite_with_origin switch
Before this commit, if `original_path` is given, it will always be used to overwrite `path`. After this commit, it's controlled by the newly-added switch `overwrite_with_origin`.
Diffstat (limited to 'src/shared/edit-util.c')
-rw-r--r--src/shared/edit-util.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c
index 097ef6a791..f482c2ac8b 100644
--- a/src/shared/edit-util.c
+++ b/src/shared/edit-util.c
@@ -129,9 +129,11 @@ static int create_edit_temp_file(EditFile *e) {
has_original = e->original_path && access(e->original_path, F_OK) >= 0;
has_target = access(e->path, F_OK) >= 0;
- if (has_original)
+ if (has_original && (!has_target || e->context->overwrite_with_origin))
+ /* We are asked to overwrite target with original_path or target doesn't exist. */
source = e->original_path;
else if (has_target)
+ /* Target exists and shouldn't be overwritten. */
source = e->path;
else
source = NULL;