fix s3 mtime problem

This commit is contained in:
fyears 2024-05-06 23:41:48 +08:00
parent 757eb5c801
commit ed52a8542f

View File

@ -340,13 +340,14 @@ const fromS3ObjectToEntity = (
const fromS3HeadObjectToEntity = ( const fromS3HeadObjectToEntity = (
fileOrFolderPathWithRemotePrefix: string, fileOrFolderPathWithRemotePrefix: string,
x: HeadObjectCommandOutput, x: HeadObjectCommandOutput,
remotePrefix: string remotePrefix: string,
useAccurateMTime: boolean
) => { ) => {
// console.debug(`fromS3HeadObjectToEntity: ${fileOrFolderPathWithRemotePrefix}: ${JSON.stringify(x,null,2)}`); // console.debug(`fromS3HeadObjectToEntity: ${fileOrFolderPathWithRemotePrefix}: ${JSON.stringify(x,null,2)}`);
// S3 officially only supports seconds precision!!!!! // S3 officially only supports seconds precision!!!!!
const mtimeSvr = Math.floor(x.LastModified!.valueOf() / 1000.0) * 1000; const mtimeSvr = Math.floor(x.LastModified!.valueOf() / 1000.0) * 1000;
let mtimeCli = mtimeSvr; let mtimeCli = mtimeSvr;
if (x.Metadata !== undefined) { if (useAccurateMTime && x.Metadata !== undefined) {
const m2 = Math.floor( const m2 = Math.floor(
parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0") 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<Entity> { async mkdir(key: string, mtime?: number, ctime?: number): Promise<Entity> {