Skip to content

Commit

Permalink
Rollback last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Dec 25, 2024
1 parent 1b874a7 commit 622c869
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion misc/clifmrc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
# confirmation prompts. Each field has two values separated by a colon (':').
#
# The left value specifies a confirmation prompt:
# 'o': overwrite files (mostly 'c', 'm', and 'n' commands)
# 'o': overwrite files (mostly 'c' and 'm' commands)
# 'r': remove ('r' command)
# 't': trash ('t' command)
# 'R': bulk rename ('br' command)
Expand Down
29 changes: 17 additions & 12 deletions src/file_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,19 +708,21 @@ format_new_filename(char **name)
}

static int
ask_overwrite(char *file, const char *cmd_name)
err_file_exists(char *name, const int multi, const int is_md)
{
char *n = abbreviate_file_name(file);
char *p = n ? n : file;
char *n = abbreviate_file_name(name);
char *p = n ? n : name;

char msg[PATH_MAX + 3 + 27];
snprintf(msg, sizeof(msg), _("%s: '%s': Overwrite this file?"),
cmd_name, (*p == '.' && p[1] == '/' && p[2]) ? p + 2 : p);
xerror("%s: '%s': %s\n", is_md ? "md" : "new",
(*p == '.' && p[1] == '/' && p[2]) ? p + 2 : p, strerror(EEXIST));

if (n && n != file)
if (n && n != name)
free(n);

return rl_get_y_or_n(msg, conf.default_answer.overwrite);
if (multi == 1)
press_any_key_to_continue(0);

return FUNC_FAILURE;
}

/* Ask the user for a new file name and create the file. */
Expand Down Expand Up @@ -751,8 +753,10 @@ ask_and_create_file(void)
goto ERROR;

struct stat a;
if (lstat(filename, &a) == 0 && ask_overwrite(filename, "new") == 0)
if (lstat(filename, &a) == 0) {
exit_status = err_file_exists(filename, 0, 0);
goto ERROR;
}

exit_status = create_file(filename, 0);
if (exit_status == FUNC_SUCCESS) {
Expand Down Expand Up @@ -828,10 +832,11 @@ create_files(char **args, const int is_md)
continue;
}

/* Warn about existent files. */
if (check_file_existence(args[i]) == 0
&& ask_overwrite(args[i], is_md == 1 ? "md" : "new") == 0)
/* Skip existent files. */
if (check_file_existence(args[i]) == 0) {
exit_status = err_file_exists(args[i], 0, is_md);
continue;
}

const int ret = create_file(args[i], is_md);
if (ret == FUNC_SUCCESS) {
Expand Down

0 comments on commit 622c869

Please sign in to comment.