diff options
author | leo-arch <leonardoabramovich2@gmail.com> | 2022-07-26 19:50:55 -0300 |
---|---|---|
committer | leo-arch <leonardoabramovich2@gmail.com> | 2022-07-26 19:50:55 -0300 |
commit | cd41ec4ab9128e08b7563e293bfd62b0169cb044 (patch) | |
tree | f8ea9f28f2818b757f8f42c538387af2ca8b0a20 | |
parent | 0ef5556390da642a1c8ba22a63e628c309a74724 (diff) |
Fix failed glob in bulk rename
-rw-r--r-- | src/file_operations.c | 22 | ||||
-rw-r--r-- | src/mime.c | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/file_operations.c b/src/file_operations.c index 7a27279f..b0083b87 100644 --- a/src/file_operations.c +++ b/src/file_operations.c @@ -544,7 +544,7 @@ bulk_remove(char *s1, char *s2) } #ifndef _NO_LIRA -static inline int +static int run_mime(char *file) { if (!file || !*file) @@ -1586,8 +1586,8 @@ bulk_rename(char **args) } #endif -#define BULK_MESSAGE "# Edit the file names, save, and quit the editor\n\ -# Just quit the editor to cancel the operation\n\n" +#define BULK_MESSAGE "# Edit file names, save, and quit the editor\n\ +# Just quit the editor without any edit to cancel the operation\n\n" #ifndef __HAIKU__ dprintf(fd, BULK_MESSAGE); @@ -1595,6 +1595,8 @@ bulk_rename(char **args) fprintf(fp, BULK_MESSAGE); #endif + struct stat attr; + size_t counter = 0; /* Copy all files to be renamed to the bulk file */ for (i = 1; args[i]; i++) { /* Dequote file name, if necessary */ @@ -1608,6 +1610,13 @@ bulk_rename(char **args) strcpy(args[i], deq_file); free(deq_file); } + if (lstat(args[i], &attr) == -1) { /* Ex: in case of failed glob */ + fprintf(stderr, "br: %s: %s\n", args[i], strerror(errno)); + continue; + } else { + counter++; + } + #ifndef __HAIKU__ dprintf(fd, "%s\n", args[i]); #else @@ -1620,6 +1629,9 @@ bulk_rename(char **args) arg_total = i; close(fd); + if (counter == 0) + return EXIT_FAILURE; + fp = open_fstream_r(bulk_file, &fd); if (!fp) { _err('e', PRINT_PROMPT, "br: %s: %s\n", bulk_file, strerror(errno)); @@ -1629,7 +1641,7 @@ bulk_rename(char **args) /* Store the last modification time of the bulk file. This time * will be later compared to the modification time of the same * file after shown to the user */ - struct stat attr; +// struct stat attr; fstat(fd, &attr); time_t mtime_bfr = (time_t)attr.st_mtime; @@ -1657,7 +1669,7 @@ bulk_rename(char **args) * match, nothing was modified */ fstat(fd, &attr); if (mtime_bfr == (time_t)attr.st_mtime) { - puts(_("bulk: Nothing to do")); + puts(_("br: Nothing to do")); if (unlinkat(fd, bulk_file, 0) == -1) { _err('e', PRINT_PROMPT, "br: unlinkat: %s: %s\n", bulk_file, strerror(errno)); exit_status = EXIT_FAILURE; @@ -1457,7 +1457,7 @@ get_open_file_path(char **args, char **fpath, char **deq) /* Handle mime when no opening app has been found */ static int -handle_no_app(int info, char **fpath, char **mime, char *arg) +handle_no_app(const int info, char **fpath, char **mime, const char *arg) { if (info) { fputs(_("Associated application: None\n"), stderr); |