mirror of
https://github.com/jarun/nnn.git
synced 2025-03-18 20:39:45 +00:00
Ignore . and .. in file list
This commit is contained in:
parent
ae486e36b8
commit
0a48b6b8cc
1 changed files with 22 additions and 26 deletions
48
src/nnn.c
48
src/nnn.c
|
@ -947,11 +947,17 @@ static void *xmemrchr(uchar *s, uchar ch, size_t n)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assumes both the paths passed are directories */
|
||||||
static char *common_prefix(const char *s, char *prefix)
|
static char *common_prefix(const char *s, char *prefix)
|
||||||
{
|
{
|
||||||
if (!s || !prefix)
|
if (!s || !*s || !prefix)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (!*prefix) {
|
||||||
|
xstrlcpy(prefix, s, PATH_MAX);
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
/* Only accept non-empty strings */
|
/* Only accept non-empty strings */
|
||||||
if (*s == '\0' || *prefix == '\0')
|
if (*s == '\0' || *prefix == '\0')
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4176,6 +4182,12 @@ static blkcnt_t dirwalk(char *path, struct stat *psb)
|
||||||
return ent_blocks;
|
return ent_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Skip self and parent */
|
||||||
|
static bool selforparent(char *path)
|
||||||
|
{
|
||||||
|
return path[0] == '.' && (path[1] == '\0' || (path[1] == '.' && path[2] == '\0'));
|
||||||
|
}
|
||||||
|
|
||||||
static int dentfill(char *path, struct entry **dents)
|
static int dentfill(char *path, struct entry **dents)
|
||||||
{
|
{
|
||||||
int n = 0, count, flags = 0;
|
int n = 0, count, flags = 0;
|
||||||
|
@ -4230,8 +4242,7 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
do {
|
do {
|
||||||
namep = dp->d_name;
|
namep = dp->d_name;
|
||||||
|
|
||||||
/* Skip self and parent */
|
if (selforparent(namep))
|
||||||
if ((namep[0] == '.' && (namep[1] == '\0' || (namep[1] == '.' && namep[2] == '\0'))))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cfg.showhidden && namep[0] == '.') {
|
if (!cfg.showhidden && namep[0] == '.') {
|
||||||
|
@ -6057,6 +6068,9 @@ static char *make_tmp_tree(char **paths, ssize_t entries, const char *prefix)
|
||||||
g_listpath = tmpdir;
|
g_listpath = tmpdir;
|
||||||
|
|
||||||
for (i = 0; i < entries; ++i) {
|
for (i = 0; i < entries; ++i) {
|
||||||
|
if (!paths[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
err = stat(paths[i], &sb);
|
err = stat(paths[i], &sb);
|
||||||
if (err && errno == ENOENT) {
|
if (err && errno == ENOENT) {
|
||||||
ignore = 1;
|
ignore = 1;
|
||||||
|
@ -6096,10 +6110,9 @@ static char *load_input()
|
||||||
ssize_t i, chunk_count = 1, chunk = 512 * 1024, entries = 0;
|
ssize_t i, chunk_count = 1, chunk = 512 * 1024, entries = 0;
|
||||||
char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL;
|
char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL;
|
||||||
char cwd[PATH_MAX], *next, *tmp;
|
char cwd[PATH_MAX], *next, *tmp;
|
||||||
size_t offsets[LIST_FILES_MAX], len;
|
size_t offsets[LIST_FILES_MAX];
|
||||||
char **paths = NULL;
|
char **paths = NULL;
|
||||||
ssize_t input_read, total_read = 0, off = 0;
|
ssize_t input_read, total_read = 0, off = 0;
|
||||||
bool dotfirst = FALSE;
|
|
||||||
|
|
||||||
if (!input) {
|
if (!input) {
|
||||||
DPRINTF_S(strerror(errno));
|
DPRINTF_S(strerror(errno));
|
||||||
|
@ -6183,31 +6196,14 @@ static char *load_input()
|
||||||
g_prefixpath = malloc(sizeof(char) * PATH_MAX);
|
g_prefixpath = malloc(sizeof(char) * PATH_MAX);
|
||||||
if (!g_prefixpath)
|
if (!g_prefixpath)
|
||||||
goto malloc_1;
|
goto malloc_1;
|
||||||
|
g_prefixpath[0] = '\0';
|
||||||
if (paths[0][0] == '.' && paths[0][1] == '\0')
|
|
||||||
dotfirst = TRUE;
|
|
||||||
|
|
||||||
if (!(paths[0] = realpath(paths[0], NULL)))
|
|
||||||
goto malloc_1; // free all entries
|
|
||||||
|
|
||||||
DPRINTF_S(paths[0]);
|
DPRINTF_S(paths[0]);
|
||||||
|
|
||||||
if (dotfirst) {
|
for (i = 0; i < entries; ++i) {
|
||||||
xstrlcpy(g_prefixpath, paths[0], strlen(paths[0]) + 1);
|
if (selforparent(paths[i]))
|
||||||
i = 1; /* start enumerating from first file */
|
continue;
|
||||||
} else {
|
|
||||||
xstrlcpy(g_buf, paths[0], PATH_MAX);
|
|
||||||
len = strlen(dirname(g_buf));
|
|
||||||
|
|
||||||
/* dirname() may modify the original path */
|
|
||||||
xstrlcpy(g_buf, paths[0], PATH_MAX);
|
|
||||||
xstrlcpy(g_prefixpath, dirname(g_buf), len + 1);
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF_S(g_prefixpath);
|
|
||||||
|
|
||||||
for (; i < entries; ++i) {
|
|
||||||
if (!(paths[i] = realpath(paths[i], NULL))) {
|
if (!(paths[i] = realpath(paths[i], NULL))) {
|
||||||
entries = i; // free from the previous entry
|
entries = i; // free from the previous entry
|
||||||
goto malloc_2;
|
goto malloc_2;
|
||||||
|
|
Loading…
Add table
Reference in a new issue