From 623c49e43906d3f86fb3c2470ae18916a03673a4 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Sun, 20 Mar 2022 20:32:03 -0700 Subject: [PATCH] File's meta-object's "size" and "time" properties reflect current values Query the disk for file's current "size" and "time" values when get_list() or get() method is used with a "detail" level of >= DETAIL.NORMAL and the "check file existence" toggle option is enabled for this directory in SCFG. I pondered and contemplated whether this configuration setting should be checked/applied here or in the various JS scripts (e.g. filelist.js) and decided here was best to provide the most uniform/expected behavior, even though there is a performance impact. If a script doesn't need/use these properties, they should probably be specifying the DETAIL.MIN (minimal) detail level in their queries anyway, which will then bypass these performance-impacting disk queries. --- src/sbbs3/js_filebase.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sbbs3/js_filebase.c b/src/sbbs3/js_filebase.c index 5e9a4f294d..cdfe4ff4f4 100644 --- a/src/sbbs3/js_filebase.c +++ b/src/sbbs3/js_filebase.c @@ -251,11 +251,17 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de if(!JS_DefineProperty(cx, obj, "cost", val, NULL, NULL, flags)) return false; } - val = UINT_TO_JSVAL(f->idx.size); + if(is_valid_dirnum(scfg, f->dir) && (scfg->dir[f->dir]->misc & DIR_FCHK) && detail >= file_detail_normal) + val = DOUBLE_TO_JSVAL((double)getfilesize(scfg, f)); + else + val = UINT_TO_JSVAL(f->idx.size); if(!JS_DefineProperty(cx, obj, "size", val, NULL, NULL, flags)) return false; - val = UINT_TO_JSVAL(f->hdr.when_written.time); + if(is_valid_dirnum(scfg, f->dir) && (scfg->dir[f->dir]->misc & DIR_FCHK) && detail >= file_detail_normal) + val = DOUBLE_TO_JSVAL((double)getfiletime(scfg, f)); + else + val = UINT_TO_JSVAL(f->hdr.when_written.time); if(!JS_DefineProperty(cx, obj, "time", val, NULL, NULL, flags)) return false; if(f->hdr.when_imported.time > 0 || detail > file_detail_metadata) { -- GitLab