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`.
}
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())
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;
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);
.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;