From ed52a8542fdd20aa0993365d6b585cd9fcb5a0f2 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 6 May 2024 23:41:48 +0800 Subject: [PATCH] fix s3 mtime problem --- src/fsS3.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fsS3.ts b/src/fsS3.ts index eec4c3e..9d2a802 100644 --- a/src/fsS3.ts +++ b/src/fsS3.ts @@ -340,13 +340,14 @@ const fromS3ObjectToEntity = ( const fromS3HeadObjectToEntity = ( fileOrFolderPathWithRemotePrefix: string, x: HeadObjectCommandOutput, - remotePrefix: string + remotePrefix: string, + useAccurateMTime: boolean ) => { // console.debug(`fromS3HeadObjectToEntity: ${fileOrFolderPathWithRemotePrefix}: ${JSON.stringify(x,null,2)}`); // S3 officially only supports seconds precision!!!!! const mtimeSvr = Math.floor(x.LastModified!.valueOf() / 1000.0) * 1000; let mtimeCli = mtimeSvr; - if (x.Metadata !== undefined) { + if (useAccurateMTime && x.Metadata !== undefined) { const m2 = Math.floor( parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0") ); @@ -561,7 +562,12 @@ export class FakeFsS3 extends FakeFs { }) ); - return fromS3HeadObjectToEntity(key, res, this.s3Config.remotePrefix ?? ""); + return fromS3HeadObjectToEntity( + key, + res, + this.s3Config.remotePrefix ?? "", + this.s3Config.useAccurateMTime ?? false + ); } async mkdir(key: string, mtime?: number, ctime?: number): Promise {