]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #1201: accept link name for single target
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 19 Oct 2021 10:05:57 +0000 (15:35 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 19 Oct 2021 10:05:57 +0000 (15:35 +0530)
When creating new sym/hard link, accept link name if
the current file is being linked or 1 file selected.

src/nnn.c

index a79387beafdbdc0f477e4ad7588cfacb8a359078..8499489aa8691e34fb7e5be9eb759d110df2646e 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3685,14 +3685,15 @@ static int xlink(char *prefix, char *path, char *curfname, char *buf, int *prese
        else /* hard link */
                link_fn = &link;
 
-       if (choice == 'c') {
-               r = xstrsncpy(buf, prefix, NAME_MAX + 1); /* Copy prefix */
-               xstrsncpy(buf + r - 1, curfname, NAME_MAX - r); /* Suffix target file name */
-               mkpath(path, buf, lnpath); /* Generate link path */
-               mkpath(path, curfname, buf); /* Generate target file path */
+       if (choice == 'c' || (nselected == 1)) {
+               mkpath(path, prefix, lnpath); /* Generate link path */
+               mkpath(path, (choice == 'c') ? curfname : pselbuf, buf); /* Generate target file path */
 
-               if (!link_fn(buf, lnpath))
+               if (!link_fn(buf, lnpath)) {
+                       if (choice == 's')
+                               clearselection();
                        return 1; /* One link created */
+               }
 
                printwarn(presel);
                return -1;
@@ -7442,7 +7443,8 @@ nochange:
                                if (r == 'f' || r == 'd')
                                        tmp = xreadline(NULL, messages[MSG_NEW_PATH]);
                                else if (r == 's' || r == 'h')
-                                       tmp = xreadline(NULL, messages[MSG_LINK_PREFIX]);
+                                       tmp = xreadline(NULL,
+                                               messages[nselected <= 1?MSG_NEW_PATH:MSG_LINK_PREFIX]);
                                else
                                        tmp = NULL;
                                break;