mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Handle the root path case correctly
This commit is contained in:
parent
61cd0f8041
commit
3277201075
19
noice.c
19
noice.c
|
@ -374,8 +374,12 @@ begin:
|
||||||
dents[n].name = strdup(dp->d_name);
|
dents[n].name = strdup(dp->d_name);
|
||||||
if (dents[n].name == NULL)
|
if (dents[n].name == NULL)
|
||||||
printerr(1, "strdup");
|
printerr(1, "strdup");
|
||||||
/* Get mode flags */
|
/* Handle root case */
|
||||||
|
if (strcmp(path, "/") == 0)
|
||||||
|
asprintf(&name, "/%s", dents[n].name);
|
||||||
|
else
|
||||||
asprintf(&name, "%s/%s", path, dents[n].name);
|
asprintf(&name, "%s/%s", path, dents[n].name);
|
||||||
|
/* Get mode flags */
|
||||||
r = lstat(name, &sb);
|
r = lstat(name, &sb);
|
||||||
free(name);
|
free(name);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
|
@ -406,7 +410,7 @@ redraw:
|
||||||
erase();
|
erase();
|
||||||
|
|
||||||
/* Strip trailing slashes */
|
/* Strip trailing slashes */
|
||||||
for (i = strlen(path) - 1; i > -1; i--)
|
for (i = strlen(path) - 1; i > 0; i--)
|
||||||
if (path[i] == '/')
|
if (path[i] == '/')
|
||||||
path[i] = '\0';
|
path[i] = '\0';
|
||||||
else
|
else
|
||||||
|
@ -420,12 +424,7 @@ redraw:
|
||||||
strlcpy(cwd, path, COLS * sizeof(char));
|
strlcpy(cwd, path, COLS * sizeof(char));
|
||||||
cwd[COLS - strlen(CWD) - 1] = '\0';
|
cwd[COLS - strlen(CWD) - 1] = '\0';
|
||||||
|
|
||||||
/* Print cwd. If empty we are on the root. We store it
|
printw(CWD "%s\n\n", cwd);
|
||||||
* as an empty string so that when we navigate in /mnt
|
|
||||||
* is doesn't come up as //mnt. */
|
|
||||||
printw(CWD "%s%s\n\n",
|
|
||||||
strcmp(cwd, "") == 0 ? "/" : "",
|
|
||||||
cwd);
|
|
||||||
|
|
||||||
/* Print listing */
|
/* Print listing */
|
||||||
odd = ISODD(nlines);
|
odd = ISODD(nlines);
|
||||||
|
@ -449,8 +448,8 @@ nochange:
|
||||||
free(filter);
|
free(filter);
|
||||||
return;
|
return;
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
/* Handle root case */
|
/* There is no going back */
|
||||||
if (strcmp(path, "") == 0) {
|
if (strcmp(path, "/") == 0) {
|
||||||
goto nochange;
|
goto nochange;
|
||||||
} else {
|
} else {
|
||||||
dir = dirname(path);
|
dir = dirname(path);
|
||||||
|
|
Loading…
Reference in a new issue