]> Sergey Matveev's repositories - nnn.git/commitdiff
Allow overwriting regular files on new empty file creation
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 10 Dec 2022 13:51:56 +0000 (19:21 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 10 Dec 2022 13:58:58 +0000 (19:28 +0530)
src/nnn.c

index 9b0c502da5b287afe7c5b6021509b1ff2201541a..f5a170de535c3ffece7b489ffddadcd1792454b5 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4556,7 +4556,7 @@ next:
                        return FALSE;
                }
        } else {
-               int fd = open(path, O_CREAT, 0666);
+               int fd = open(path, O_CREAT | O_TRUNC, 0666); /* Use forced create mode for files */
 
                if (fd == -1 && errno != EEXIST) {
                        DPRINTF_S("open!");
@@ -7612,14 +7612,14 @@ nochange:
 
                        /* Check if another file with same name exists */
                        if (fstatat(fd, tmp, &sb, AT_SYMLINK_NOFOLLOW) == 0) {
-                               if (sel == SEL_RENAME) {
+                               if ((sel == SEL_RENAME) || ((r == 'f') && (S_ISREG(sb.st_mode)))) {
                                        /* Overwrite file with same name? */
                                        if (!xconfirm(get_input(messages[MSG_OVERWRITE]))) {
                                                close(fd);
                                                break;
                                        }
                                } else {
-                                       /* Do nothing in case of NEW */
+                                       /* Do nothing for SEL_NEW if a non-regular entry exists */
                                        close(fd);
                                        printwait(messages[MSG_EXISTS], &presel);
                                        goto nochange;