Fix displaying and exporting zero values when extended info is not available

Backport from 2.6.
This commit is contained in:
Yorhel 2024-11-15 14:37:44 +01:00
parent bc8129cad1
commit 73ef3294e8
5 changed files with 41 additions and 15 deletions

View file

@ -68,15 +68,21 @@ static void browse_draw_info(struct dir *dr) {
ncaddstr(2, 9, cropstr(dr->name, 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;
ncaddstr(4, 9, fmtmode(e->mode));
ncprint(4, 26, "%d", e->uid);
ncprint(4, 38, "%d", e->gid);
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
ncaddstr(5, 18, mbuf);
if(e->flags & FFE_MODE) ncaddstr(4, 9, fmtmode(e->mode));
else ncaddstr(4, 9, "N/A");
if(e->flags & FFE_UID) ncprint(4, 26, "%d", e->uid);
else ncaddstr(4, 26, "N/A");
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);

View file

@ -98,14 +98,22 @@ static void output_info(struct dir *d, const char *name, struct dir_ext *e, unsi
}
if(e) {
fputs(",\"uid\":", stream);
output_int(e->uid);
fputs(",\"gid\":", stream);
output_int(e->gid);
fputs(",\"mode\":", stream);
output_int(e->mode);
fputs(",\"mtime\":", stream);
output_int(e->mtime);
if(e->flags & FFE_UID) {
fputs(",\"uid\":", stream);
output_int(e->uid);
}
if(e->flags & FFE_GID) {
fputs(",\"gid\":", stream);
output_int(e->gid);
}
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) {

View file

@ -471,18 +471,22 @@ static int iteminfo(void) {
} else if(strcmp(ctx->val, "uid") == 0) { /* uid */
C(rint64(&iv, INT32_MAX));
ctx->buf_dir->flags |= FF_EXT;
ctx->buf_ext->flags |= FFE_UID;
ctx->buf_ext->uid = iv;
} else if(strcmp(ctx->val, "gid") == 0) { /* gid */
C(rint64(&iv, INT32_MAX));
ctx->buf_dir->flags |= FF_EXT;
ctx->buf_ext->flags |= FFE_GID;
ctx->buf_ext->gid = iv;
} else if(strcmp(ctx->val, "mode") == 0) { /* mode */
C(rint64(&iv, UINT16_MAX));
ctx->buf_dir->flags |= FF_EXT;
ctx->buf_ext->flags |= FFE_MODE;
ctx->buf_ext->mode = iv;
} else if(strcmp(ctx->val, "mtime") == 0) { /* mtime */
C(rint64(&iv, UINT64_MAX));
ctx->buf_dir->flags |= FF_EXT;
ctx->buf_ext->flags |= FFE_MTIME;
ctx->buf_ext->mtime = iv;
/* Accept decimal numbers, but discard the fractional part because our data model doesn't support it. */
if(*ctx->buf == '.') {

View file

@ -139,6 +139,7 @@ static void stat_to_dir(struct stat *fs) {
buf_ext->mtime = fs->st_mtime;
buf_ext->uid = (int)fs->st_uid;
buf_ext->gid = (int)fs->st_gid;
buf_ext->flags = FFE_MTIME | FFE_UID | FFE_GID | FFE_MODE;
}

View file

@ -54,6 +54,12 @@
#define FF_KERNFS 0x200 /* excluded because it was a Linux pseudo filesystem */
#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 */
#define ST_CALC 0
#define ST_BROWSE 1
@ -90,6 +96,7 @@ struct dir_ext {
uint64_t mtime;
int uid, gid;
unsigned short mode;
unsigned char flags;
};