Resolve path in list mode

This commit is contained in:
Arun Prakash Jana 2020-04-25 20:36:10 +05:30
parent 06fe7d52dd
commit c732de32e4
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1138,12 +1138,12 @@ static void appendfpath(const char *path, const size_t len)
} }
/* Write selected file paths to fd, linefeed separated */ /* Write selected file paths to fd, linefeed separated */
static size_t seltofile(int fd, uint *pcount, bool tgt) static size_t seltofile(int fd, uint *pcount)
{ {
uint lastpos, count = 0; uint lastpos, count = 0;
char *pbuf = pselbuf; char *pbuf = pselbuf;
size_t pos = 0; size_t pos = 0;
ssize_t len, prefixlen, initlen; ssize_t len, prefixlen = 0, initlen = 0;
if (pcount) if (pcount)
*pcount = 0; *pcount = 0;
@ -1153,7 +1153,7 @@ static size_t seltofile(int fd, uint *pcount, bool tgt)
lastpos = selbufpos - 1; lastpos = selbufpos - 1;
if (tgt) { if (listpath) {
prefixlen = (ssize_t)xstrlen(prefixpath); prefixlen = (ssize_t)xstrlen(prefixpath);
initlen = (ssize_t)xstrlen(initpath); initlen = (ssize_t)xstrlen(initpath);
} }
@ -1162,7 +1162,7 @@ static size_t seltofile(int fd, uint *pcount, bool tgt)
DPRINTF_S(pbuf); DPRINTF_S(pbuf);
len = (ssize_t)xstrlen(pbuf); len = (ssize_t)xstrlen(pbuf);
if (!tgt || (strncmp(initpath, pbuf, initlen) != 0)) { if (!listpath || strncmp(initpath, pbuf, initlen) != 0) {
if (write(fd, pbuf, len) != len) if (write(fd, pbuf, len) != len)
return pos; return pos;
} else { } else {
@ -1260,7 +1260,7 @@ static void endselection(void)
return; return;
} }
seltofile(fd, NULL, FALSE); seltofile(fd, NULL);
if (close(fd)) { if (close(fd)) {
DPRINTF_S(strerror(errno)); DPRINTF_S(strerror(errno));
printwarn(NULL); printwarn(NULL);
@ -1332,7 +1332,7 @@ static int editselection(void)
return -1; return -1;
} }
seltofile(fd, NULL, FALSE); seltofile(fd, NULL);
if (close(fd)) { if (close(fd)) {
DPRINTF_S(strerror(errno)); DPRINTF_S(strerror(errno));
return -1; return -1;
@ -1803,7 +1803,7 @@ static bool cpmv_rename(int choice, const char *path)
if (!count) if (!count)
goto finish; goto finish;
} else } else
seltofile(fd, &count, FALSE); seltofile(fd, &count);
close(fd); close(fd);
@ -1913,8 +1913,8 @@ static bool batch_rename(const char *path)
for (i = 0; i < ndents; ++i) for (i = 0; i < ndents; ++i)
appendfpath(dents[i].name, NAME_MAX); appendfpath(dents[i].name, NAME_MAX);
seltofile(fd1, &count, FALSE); seltofile(fd1, &count);
seltofile(fd2, NULL, FALSE); seltofile(fd2, NULL);
close(fd2); close(fd2);
if (dir) /* Don't retain dir entries in selection */ if (dir) /* Don't retain dir entries in selection */
@ -6673,7 +6673,7 @@ int main(int argc, char *argv[])
{ {
char *arg = NULL; char *arg = NULL;
char *session = NULL; char *session = NULL;
int opt, sort = 0; int fd, opt, sort = 0;
#ifndef NOMOUSE #ifndef NOMOUSE
mmask_t mask; mmask_t mask;
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0"); char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
@ -6740,15 +6740,10 @@ int main(int argc, char *argv[])
break; break;
cfg.picker = 1; cfg.picker = 1;
if (optarg[0] == '-' && optarg[1] == '\0') { if (optarg[0] == '-' && optarg[1] == '\0')
cfg.pickraw = 1; cfg.pickraw = 1;
if (!isatty(STDOUT_FILENO)) { else {
fprintf(stderr, "stdout !tty\n"); fd = open(optarg, O_WRONLY | O_CREAT, 0600);
return _FAILURE;
}
} else {
int fd = open(optarg, O_WRONLY | O_CREAT, 0600);
if (fd == -1) { if (fd == -1) {
xerror(); xerror();
return _FAILURE; return _FAILURE;
@ -7018,9 +7013,8 @@ int main(int argc, char *argv[])
if (cfg.pickraw || cfg.picker) { if (cfg.pickraw || cfg.picker) {
if (selbufpos) { if (selbufpos) {
int fd = cfg.pickraw ? 1 : open(selpath, O_WRONLY | O_CREAT, 0600); fd = cfg.pickraw ? 1 : open(selpath, O_WRONLY | O_CREAT, 0600);
if ((fd == -1) || (seltofile(fd, NULL) != (size_t)(selbufpos)))
if ((fd == -1) || (seltofile(fd, NULL, TRUE) != (size_t)(selbufpos)))
xerror(); xerror();
if (fd > 1) if (fd > 1)