diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 6a29a32bcd..7eb2235667 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1454,9 +1454,7 @@ static int get_settings_path(const char *name, char **ret_path) { } static int edit_settings(int argc, char *argv[], void *userdata) { - _cleanup_(edit_file_context_done) EditFileContext context = { - .remove_parent = false, - }; + _cleanup_(edit_file_context_done) EditFileContext context = {}; int r; if (!on_tty()) 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; diff --git a/src/shared/edit-util.h b/src/shared/edit-util.h index e57ca80a49..83b3df8683 100644 --- a/src/shared/edit-util.h +++ b/src/shared/edit-util.h @@ -24,6 +24,7 @@ struct EditFileContext { const char *marker_start; const char *marker_end; bool remove_parent; + bool overwrite_with_origin; /* whether to always overwrite target with original file */ }; void edit_file_context_done(EditFileContext *context); diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index ff16b73229..561b01a67a 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -316,6 +316,7 @@ int verb_edit(int argc, char *argv[], void *userdata) { .marker_start = DROPIN_MARKER_START, .marker_end = DROPIN_MARKER_END, .remove_parent = !arg_full, + .overwrite_with_origin = true, }; _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_strv_free_ char **names = NULL;