From 328a004631a281da5b4c6534507501ef765bf232 Mon Sep 17 00:00:00 2001 From: zaihuaji Date: Thu, 17 Sep 2026 09:11:05 -0500 Subject: [PATCH] pg_file.py: report the newest member time for object directory keys; bump version to 3.0.17 check_object_file() took the timestamp of whichever member the listing happened to return first for a key prefix such as a zarr store. The newest member's timestamp is reported instead, which is what the file as a whole was last modified at. Co-Authored-By: Claude Opus 4.6 --- README.md | 2 +- pyproject.toml | 2 +- src/rda_python_common/__init__.py | 2 +- src/rda_python_common/pg_file.py | 23 ++++++++++++----------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index edce822..bc12b52 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN) python -c "import rda_python_common; print(rda_python_common.__version__)" ``` -You should see the installed version (currently `3.0.16`). If the import +You should see the installed version (currently `3.0.17`). If the import fails, double-check that the active Python environment is the one where you ran `pip install`. diff --git a/pyproject.toml b/pyproject.toml index 34e23b0..0b5a259 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "rda_python_common" -version = "3.0.16" +version = "3.0.17" authors = [ { name="Zaihua Ji", email="zji@ucar.edu" }, ] diff --git a/src/rda_python_common/__init__.py b/src/rda_python_common/__init__.py index e406c96..7d398ce 100644 --- a/src/rda_python_common/__init__.py +++ b/src/rda_python_common/__init__.py @@ -22,7 +22,7 @@ from . import PgLOG, PgUtil, PgDBI, PgFile, PgLock, PgCMD, PgSIG, PgOPT, PgSplit -__version__ = "3.0.16" +__version__ = "3.0.17" __all__ = [ "PgLOG", diff --git a/src/rda_python_common/pg_file.py b/src/rda_python_common/pg_file.py index d96eded..e63cf7c 100644 --- a/src/rda_python_common/pg_file.py +++ b/src/rda_python_common/pg_file.py @@ -2357,22 +2357,23 @@ def check_object_file(self, file, bucket = None, opt = 0, logact = 0): if re.match(r'^\[\]', buf): break if re.match(r'^\[\{', buf): ary = json.loads(buf) - hash = ary[0] + cnt = len(ary) + isdir = (cnt > 1 or ary[0]['Key'] != file) + # a key prefix has no timestamp of its own; report the newest member's + hash = max(ary, key = lambda a: a['LastModified']) if isdir else ary[0] uhash = None if ucmd: ubuf = self.pgsystem(ucmd, self.LOGWRN, self.CMDRET) if ubuf and re.match(r'^\{', ubuf): uhash = json.loads(ubuf) ret = self.object_file_stat(hash, uhash, opt) - if ret: - cnt = len(ary) - if cnt > 1 or hash['Key'] != file: - ret['count'] = cnt - ret['fname'] = op.basename(file) - ret['isfile'] = 0 - size = 0 - for a in ary: - size += int(a['Size']) - ret['data_size'] = size + if ret and isdir: + ret['count'] = cnt + ret['fname'] = op.basename(file) + ret['isfile'] = 0 + size = 0 + for a in ary: + size += int(a['Size']) + ret['data_size'] = size uhash = None break if opt&64: return self.FAILURE