mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Fix displaying and exporting zero values when extended info is not available
Backport from 2.6.
This commit is contained in:
parent
bc8129cad1
commit
73ef3294e8
5 changed files with 41 additions and 15 deletions
|
|
@ -68,15 +68,21 @@ static void browse_draw_info(struct dir *dr) {
|
||||||
|
|
||||||
ncaddstr(2, 9, cropstr(dr->name, 49));
|
ncaddstr(2, 9, cropstr(dr->name, 49));
|
||||||
ncaddstr(3, 9, cropstr(getpath(dr->parent), 49));
|
ncaddstr(3, 9, cropstr(getpath(dr->parent), 49));
|
||||||
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory" : dr->flags & FF_FILE ? "File" : "Other");
|
|
||||||
|
|
||||||
if(e) {
|
if(!e)
|
||||||
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory" : dr->flags & FF_FILE ? "File" : "Other");
|
||||||
|
else {
|
||||||
time_t t = (time_t)e->mtime;
|
time_t t = (time_t)e->mtime;
|
||||||
ncaddstr(4, 9, fmtmode(e->mode));
|
if(e->flags & FFE_MODE) ncaddstr(4, 9, fmtmode(e->mode));
|
||||||
ncprint(4, 26, "%d", e->uid);
|
else ncaddstr(4, 9, "N/A");
|
||||||
ncprint(4, 38, "%d", e->gid);
|
if(e->flags & FFE_UID) ncprint(4, 26, "%d", e->uid);
|
||||||
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
|
else ncaddstr(4, 26, "N/A");
|
||||||
ncaddstr(5, 18, mbuf);
|
if(e->flags & FFE_GID) ncprint(4, 38, "%d", e->gid);
|
||||||
|
else ncaddstr(4, 38, "N/A");
|
||||||
|
if(e->flags & FFE_MTIME) {
|
||||||
|
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
|
||||||
|
ncaddstr(5, 18, mbuf);
|
||||||
|
} else ncaddstr(5, 18, "N/A");
|
||||||
}
|
}
|
||||||
|
|
||||||
ncmove(6, 18);
|
ncmove(6, 18);
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,22 @@ static void output_info(struct dir *d, const char *name, struct dir_ext *e, unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e) {
|
if(e) {
|
||||||
fputs(",\"uid\":", stream);
|
if(e->flags & FFE_UID) {
|
||||||
output_int(e->uid);
|
fputs(",\"uid\":", stream);
|
||||||
fputs(",\"gid\":", stream);
|
output_int(e->uid);
|
||||||
output_int(e->gid);
|
}
|
||||||
fputs(",\"mode\":", stream);
|
if(e->flags & FFE_GID) {
|
||||||
output_int(e->mode);
|
fputs(",\"gid\":", stream);
|
||||||
fputs(",\"mtime\":", stream);
|
output_int(e->gid);
|
||||||
output_int(e->mtime);
|
}
|
||||||
|
if(e->flags & FFE_MODE) {
|
||||||
|
fputs(",\"mode\":", stream);
|
||||||
|
output_int(e->mode);
|
||||||
|
}
|
||||||
|
if(e->flags & FFE_MTIME) {
|
||||||
|
fputs(",\"mtime\":", stream);
|
||||||
|
output_int(e->mtime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(d->flags & FF_HLNKC) {
|
if(d->flags & FF_HLNKC) {
|
||||||
|
|
|
||||||
|
|
@ -471,18 +471,22 @@ static int iteminfo(void) {
|
||||||
} else if(strcmp(ctx->val, "uid") == 0) { /* uid */
|
} else if(strcmp(ctx->val, "uid") == 0) { /* uid */
|
||||||
C(rint64(&iv, INT32_MAX));
|
C(rint64(&iv, INT32_MAX));
|
||||||
ctx->buf_dir->flags |= FF_EXT;
|
ctx->buf_dir->flags |= FF_EXT;
|
||||||
|
ctx->buf_ext->flags |= FFE_UID;
|
||||||
ctx->buf_ext->uid = iv;
|
ctx->buf_ext->uid = iv;
|
||||||
} else if(strcmp(ctx->val, "gid") == 0) { /* gid */
|
} else if(strcmp(ctx->val, "gid") == 0) { /* gid */
|
||||||
C(rint64(&iv, INT32_MAX));
|
C(rint64(&iv, INT32_MAX));
|
||||||
ctx->buf_dir->flags |= FF_EXT;
|
ctx->buf_dir->flags |= FF_EXT;
|
||||||
|
ctx->buf_ext->flags |= FFE_GID;
|
||||||
ctx->buf_ext->gid = iv;
|
ctx->buf_ext->gid = iv;
|
||||||
} else if(strcmp(ctx->val, "mode") == 0) { /* mode */
|
} else if(strcmp(ctx->val, "mode") == 0) { /* mode */
|
||||||
C(rint64(&iv, UINT16_MAX));
|
C(rint64(&iv, UINT16_MAX));
|
||||||
ctx->buf_dir->flags |= FF_EXT;
|
ctx->buf_dir->flags |= FF_EXT;
|
||||||
|
ctx->buf_ext->flags |= FFE_MODE;
|
||||||
ctx->buf_ext->mode = iv;
|
ctx->buf_ext->mode = iv;
|
||||||
} else if(strcmp(ctx->val, "mtime") == 0) { /* mtime */
|
} else if(strcmp(ctx->val, "mtime") == 0) { /* mtime */
|
||||||
C(rint64(&iv, UINT64_MAX));
|
C(rint64(&iv, UINT64_MAX));
|
||||||
ctx->buf_dir->flags |= FF_EXT;
|
ctx->buf_dir->flags |= FF_EXT;
|
||||||
|
ctx->buf_ext->flags |= FFE_MTIME;
|
||||||
ctx->buf_ext->mtime = iv;
|
ctx->buf_ext->mtime = iv;
|
||||||
/* Accept decimal numbers, but discard the fractional part because our data model doesn't support it. */
|
/* Accept decimal numbers, but discard the fractional part because our data model doesn't support it. */
|
||||||
if(*ctx->buf == '.') {
|
if(*ctx->buf == '.') {
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ static void stat_to_dir(struct stat *fs) {
|
||||||
buf_ext->mtime = fs->st_mtime;
|
buf_ext->mtime = fs->st_mtime;
|
||||||
buf_ext->uid = (int)fs->st_uid;
|
buf_ext->uid = (int)fs->st_uid;
|
||||||
buf_ext->gid = (int)fs->st_gid;
|
buf_ext->gid = (int)fs->st_gid;
|
||||||
|
buf_ext->flags = FFE_MTIME | FFE_UID | FFE_GID | FFE_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,12 @@
|
||||||
#define FF_KERNFS 0x200 /* excluded because it was a Linux pseudo filesystem */
|
#define FF_KERNFS 0x200 /* excluded because it was a Linux pseudo filesystem */
|
||||||
#define FF_FRMLNK 0x400 /* excluded because it was a firmlink */
|
#define FF_FRMLNK 0x400 /* excluded because it was a firmlink */
|
||||||
|
|
||||||
|
/* Ext mode flags (struct dir_ext -> flags) */
|
||||||
|
#define FFE_MTIME 0x01
|
||||||
|
#define FFE_UID 0x02
|
||||||
|
#define FFE_GID 0x04
|
||||||
|
#define FFE_MODE 0x08
|
||||||
|
|
||||||
/* Program states */
|
/* Program states */
|
||||||
#define ST_CALC 0
|
#define ST_CALC 0
|
||||||
#define ST_BROWSE 1
|
#define ST_BROWSE 1
|
||||||
|
|
@ -90,6 +96,7 @@ struct dir_ext {
|
||||||
uint64_t mtime;
|
uint64_t mtime;
|
||||||
int uid, gid;
|
int uid, gid;
|
||||||
unsigned short mode;
|
unsigned short mode;
|
||||||
|
unsigned char flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue