]> Sergey Matveev's repositories - nnn.git/commitdiff
Improve archive creation handling
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 11 Dec 2022 20:50:28 +0000 (02:20 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 11 Dec 2022 21:13:23 +0000 (02:43 +0530)
src/.clang-tidy
src/nnn.c

index 245e4a0dba86286e2fc0e3774485c9bcd68fe0e3..0422c2a54f37a84df2df6cf50d6b2e8fda7b3ce0 100644 (file)
@@ -11,5 +11,5 @@ CheckOptions:
   - key:             fuchsia-restrict-system-includes.Includes
     value:           '*,-stdint.h,-stdbool.h'
   - key:             readability-function-size.StatementThreshold
-    value:           '920'
+    value:           '950'
 ...
index 6f7dc8ae7c368a767c8462182608a4939f9f9c67..91ea99a0f5bf0d6f700423c1bd36c8d58f3281e0 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -735,7 +735,7 @@ static char mv[] = "mv -i";
 #endif
 
 /* Archive commands */
-static const char * const archive_cmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
+static char * const archive_cmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
 
 /* Tokens used for path creation */
 #define TOK_BM  0
@@ -1165,18 +1165,22 @@ static char *common_prefix(const char *path, char *prefix)
 /*
  * The library function realpath() resolves symlinks.
  * If there's a symlink in file list we want to show the symlink not what it's points to.
- * Resolves ./../~ in path
+ * Resolves ./../~ in filepath
  */
-static char *abspath(const char *path, char *cwd, char *buf)
+static char *abspath(const char *filepath, char *cwd, char *buf)
 {
+       const char *path = filepath;
        bool allocated = FALSE;
 
        if (!path)
                return NULL;
 
-       if (path[0] == '~')
+       if (path[0] == '~') {
                cwd = home;
-       else if ((path[0] != '/') && !cwd) {
+               ++path;
+               if (*path == '/')
+                       ++path;
+       } else if ((path[0] != '/') && !cwd) {
                cwd = getcwd(NULL, 0);
                if (!cwd)
                        return NULL;
@@ -2681,7 +2685,7 @@ finish:
 }
 #endif
 
-static void get_archive_cmd(char *cmd, const char *archive)
+static char *get_archive_cmd(const char *archive)
 {
        uchar_t i = 3;
 
@@ -2693,7 +2697,7 @@ static void get_archive_cmd(char *cmd, const char *archive)
                i = 2;
        // else tar
 
-       xstrsncpy(cmd, archive_cmd[i], ARCHIVE_CMD_LEN);
+       return archive_cmd[i];
 }
 
 static void archive_selection(const char *cmd, const char *archive, const char *curpath)
@@ -7573,25 +7577,29 @@ nochange:
 
                        switch (sel) {
                        case SEL_ARCHIVE:
-                               if (r == 'c' && strcmp(tmp, pdents[cur].name) == 0)
-                                       goto nochange;
-
-                               mkpath(path, tmp, newpath);
-                               if (access(newpath, F_OK) == 0) {
+                               tmp = abspath(tmp, NULL, newpath);
+                               if (!tmp)
+                                       continue;
+                               if (access(tmp, F_OK) == 0) {
                                        if (!xconfirm(get_input(messages[MSG_OVERWRITE]))) {
                                                statusbar(path);
                                                goto nochange;
                                        }
                                }
-                               get_archive_cmd(newpath, tmp);
-                               (r == 's') ? archive_selection(newpath, tmp, path)
-                                          : spawn(newpath, tmp, pdents[cur].name,
+
+                               (r == 's') ? archive_selection(get_archive_cmd(tmp), tmp, "/")
+                                          : spawn(get_archive_cmd(tmp), tmp, pdents[cur].name,
                                                   NULL, F_CLI | F_CONFIRM);
 
-                               mkpath(path, tmp, newpath);
-                               if (access(newpath, F_OK) == 0) { /* File created */
-                                       xstrsncpy(lastname, tmp, NAME_MAX + 1);
-                                       clearfilter(); /* Archive name may not match */
+                               if (tmp && (access(tmp, F_OK) == 0)) { /* File created */
+                                       char *base = xbasename(tmp);
+                                       char *parent = xdirname(tmp);
+
+                                       /* Check if file is created in the current directory */
+                                       if (strcmp(path, parent) == 0) {
+                                               xstrsncpy(lastname, base, NAME_MAX + 1);
+                                               clearfilter(); /* Archive name may not match */
+                                       }
                                        clearselection(); /* Archive operation complete */
                                        cd = FALSE;
                                        goto begin;