mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Use single API for nftw
This commit is contained in:
parent
fce848de3c
commit
92ac068815
61
src/nnn.c
61
src/nnn.c
|
@ -3702,9 +3702,30 @@ static void dentfree(void)
|
||||||
free(dents);
|
free(dents);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dentfill(char *path, struct entry **dents)
|
static blkcnt_t dirwalk(char *path, struct stat *psb)
|
||||||
{
|
{
|
||||||
static uint open_max;
|
static uint open_max;
|
||||||
|
|
||||||
|
/* Increase current open file descriptor limit */
|
||||||
|
if (!open_max)
|
||||||
|
open_max = max_openfds();
|
||||||
|
|
||||||
|
ent_blocks = 0;
|
||||||
|
tolastln();
|
||||||
|
addstr(xbasename(path));
|
||||||
|
addstr(" [^C aborts]\n");
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
if (nftw(path, nftw_fn, open_max, FTW_MOUNT | FTW_PHYS) < 0) {
|
||||||
|
DPRINTF_S("nftw failed");
|
||||||
|
return (cfg.apparentsz ? psb->st_size : psb->st_blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ent_blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dentfill(char *path, struct entry **dents)
|
||||||
|
{
|
||||||
int n = 0, count, flags = 0;
|
int n = 0, count, flags = 0;
|
||||||
ulong num_saved;
|
ulong num_saved;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
|
@ -3729,10 +3750,6 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
printwarn(NULL);
|
printwarn(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Increase current open file descriptor limit */
|
|
||||||
if (!open_max)
|
|
||||||
open_max = max_openfds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _POSIX_C_SOURCE >= 200112L
|
#if _POSIX_C_SOURCE >= 200112L
|
||||||
|
@ -3774,20 +3791,9 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
if (sb_path.st_dev == sb.st_dev) {
|
if (sb_path.st_dev == sb.st_dev) {
|
||||||
ent_blocks = 0;
|
|
||||||
mkpath(path, namep, buf);
|
mkpath(path, namep, buf);
|
||||||
|
|
||||||
tolastln();
|
dir_blocks += dirwalk(buf, &sb);
|
||||||
addstr(xbasename(buf));
|
|
||||||
addstr(" [^C aborts]\n");
|
|
||||||
refresh();
|
|
||||||
if (nftw(buf, nftw_fn, open_max, FTW_MOUNT | FTW_PHYS) < 0) {
|
|
||||||
DPRINTF_S("nftw failed");
|
|
||||||
dir_blocks += (cfg.apparentsz
|
|
||||||
? sb.st_size
|
|
||||||
: sb.st_blocks);
|
|
||||||
} else
|
|
||||||
dir_blocks += ent_blocks;
|
|
||||||
|
|
||||||
if (interrupted) {
|
if (interrupted) {
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
@ -3875,19 +3881,11 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
|
|
||||||
if (cfg.blkorder) {
|
if (cfg.blkorder) {
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
ent_blocks = 0;
|
|
||||||
num_saved = num_files + 1;
|
num_saved = num_files + 1;
|
||||||
mkpath(path, namep, buf);
|
mkpath(path, namep, buf);
|
||||||
|
|
||||||
tolastln();
|
/* Need to show the disk usage of this dir */
|
||||||
addstr(xbasename(buf));
|
dentp->blocks = dirwalk(buf, &sb);
|
||||||
addstr(" [^C aborts]\n");
|
|
||||||
refresh();
|
|
||||||
if (nftw(buf, nftw_fn, open_max, FTW_MOUNT | FTW_PHYS) < 0) {
|
|
||||||
DPRINTF_S("nftw failed");
|
|
||||||
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
|
||||||
} else
|
|
||||||
dentp->blocks = ent_blocks;
|
|
||||||
|
|
||||||
if (sb_path.st_dev == sb.st_dev) // NOLINT
|
if (sb_path.st_dev == sb.st_dev) // NOLINT
|
||||||
dir_blocks += dentp->blocks;
|
dir_blocks += dentp->blocks;
|
||||||
|
@ -4217,16 +4215,15 @@ static void browse(char *ipath, const char *session)
|
||||||
char mark[PATH_MAX] __attribute__ ((aligned));
|
char mark[PATH_MAX] __attribute__ ((aligned));
|
||||||
char rundir[PATH_MAX] __attribute__ ((aligned));
|
char rundir[PATH_MAX] __attribute__ ((aligned));
|
||||||
char runfile[NAME_MAX + 1] __attribute__ ((aligned));
|
char runfile[NAME_MAX + 1] __attribute__ ((aligned));
|
||||||
uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
|
char *path, *lastdir, *lastname, *dir, *tmp;
|
||||||
int r = -1, fd, presel, selstartid = 0, selendid = 0;
|
|
||||||
ino_t inode = 0;
|
ino_t inode = 0;
|
||||||
enum action sel;
|
enum action sel;
|
||||||
bool dir_changed = FALSE;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *path, *lastdir, *lastname, *dir, *tmp;
|
|
||||||
MEVENT event;
|
MEVENT event;
|
||||||
struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} };
|
struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} };
|
||||||
bool currentmouse = 1;
|
int r = -1, fd, presel, selstartid = 0, selendid = 0;
|
||||||
|
const uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
|
||||||
|
bool currentmouse = 1, dir_changed = FALSE;
|
||||||
|
|
||||||
atexit(dentfree);
|
atexit(dentfree);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue