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`.
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user