fix s3 time
This commit is contained in:
parent
dcbd36e33a
commit
519fd27dd5
@ -257,7 +257,7 @@ const fromS3HeadObjectToEntity = (
|
|||||||
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 (x.Metadata !== undefined) {
|
||||||
const m2 = Math.round(
|
const m2 = Math.floor(
|
||||||
parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0")
|
parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0")
|
||||||
);
|
);
|
||||||
if (m2 !== 0) {
|
if (m2 !== 0) {
|
||||||
@ -539,12 +539,12 @@ const listFromRemoteRaw = async (
|
|||||||
if (rspHead.Metadata === undefined) {
|
if (rspHead.Metadata === undefined) {
|
||||||
// pass
|
// pass
|
||||||
} else {
|
} else {
|
||||||
mtimeRecords[content.Key!] = Math.round(
|
mtimeRecords[content.Key!] = Math.floor(
|
||||||
parseFloat(
|
parseFloat(
|
||||||
rspHead.Metadata.mtime || rspHead.Metadata.MTime || "0"
|
rspHead.Metadata.mtime || rspHead.Metadata.MTime || "0"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
ctimeRecords[content.Key!] = Math.round(
|
ctimeRecords[content.Key!] = Math.floor(
|
||||||
parseFloat(
|
parseFloat(
|
||||||
rspHead.Metadata.ctime || rspHead.Metadata.CTime || "0"
|
rspHead.Metadata.ctime || rspHead.Metadata.CTime || "0"
|
||||||
)
|
)
|
||||||
|
|||||||
31
src/sync.ts
31
src/sync.ts
@ -5,6 +5,7 @@ import type {
|
|||||||
EmptyFolderCleanType,
|
EmptyFolderCleanType,
|
||||||
Entity,
|
Entity,
|
||||||
MixedEntity,
|
MixedEntity,
|
||||||
|
SUPPORTED_SERVICES_TYPE,
|
||||||
SyncDirectionType,
|
SyncDirectionType,
|
||||||
} from "./baseTypes";
|
} from "./baseTypes";
|
||||||
import { isInsideObsFolder } from "./obsFolderLister";
|
import { isInsideObsFolder } from "./obsFolderLister";
|
||||||
@ -186,12 +187,19 @@ const isSkipItemByName = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyEntityAndFixTimeFormat = (src: Entity) => {
|
const copyEntityAndFixTimeFormat = (
|
||||||
|
src: Entity,
|
||||||
|
serviceType: SUPPORTED_SERVICES_TYPE
|
||||||
|
) => {
|
||||||
const result = Object.assign({}, src);
|
const result = Object.assign({}, src);
|
||||||
if (result.mtimeCli !== undefined) {
|
if (result.mtimeCli !== undefined) {
|
||||||
if (result.mtimeCli === 0) {
|
if (result.mtimeCli === 0) {
|
||||||
result.mtimeCli = undefined;
|
result.mtimeCli = undefined;
|
||||||
} else {
|
} else {
|
||||||
|
if (serviceType === "s3") {
|
||||||
|
// round to second instead of millisecond
|
||||||
|
result.mtimeCli = Math.floor(result.mtimeCli / 1000.0) * 1000;
|
||||||
|
}
|
||||||
result.mtimeCliFmt = unixTimeToStr(result.mtimeCli);
|
result.mtimeCliFmt = unixTimeToStr(result.mtimeCli);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,6 +207,10 @@ const copyEntityAndFixTimeFormat = (src: Entity) => {
|
|||||||
if (result.mtimeSvr === 0) {
|
if (result.mtimeSvr === 0) {
|
||||||
result.mtimeSvr = undefined;
|
result.mtimeSvr = undefined;
|
||||||
} else {
|
} else {
|
||||||
|
if (serviceType === "s3") {
|
||||||
|
// round to second instead of millisecond
|
||||||
|
result.mtimeSvr = Math.floor(result.mtimeSvr / 1000.0) * 1000;
|
||||||
|
}
|
||||||
result.mtimeSvrFmt = unixTimeToStr(result.mtimeSvr);
|
result.mtimeSvrFmt = unixTimeToStr(result.mtimeSvr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,6 +218,10 @@ const copyEntityAndFixTimeFormat = (src: Entity) => {
|
|||||||
if (result.prevSyncTime === 0) {
|
if (result.prevSyncTime === 0) {
|
||||||
result.prevSyncTime = undefined;
|
result.prevSyncTime = undefined;
|
||||||
} else {
|
} else {
|
||||||
|
if (serviceType === "s3") {
|
||||||
|
// round to second instead of millisecond
|
||||||
|
result.prevSyncTime = Math.floor(result.prevSyncTime / 1000.0) * 1000;
|
||||||
|
}
|
||||||
result.prevSyncTimeFmt = unixTimeToStr(result.prevSyncTime);
|
result.prevSyncTimeFmt = unixTimeToStr(result.prevSyncTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,7 +377,8 @@ export const ensembleMixedEnties = async (
|
|||||||
configDir: string,
|
configDir: string,
|
||||||
syncUnderscoreItems: boolean,
|
syncUnderscoreItems: boolean,
|
||||||
ignorePaths: string[],
|
ignorePaths: string[],
|
||||||
password: string
|
password: string,
|
||||||
|
serviceType: SUPPORTED_SERVICES_TYPE
|
||||||
): Promise<SyncPlanType> => {
|
): Promise<SyncPlanType> => {
|
||||||
const finalMappings: SyncPlanType = {};
|
const finalMappings: SyncPlanType = {};
|
||||||
|
|
||||||
@ -369,7 +386,7 @@ export const ensembleMixedEnties = async (
|
|||||||
for (const remote of remoteEntityList) {
|
for (const remote of remoteEntityList) {
|
||||||
const remoteCopied = ensureMTimeOfRemoteEntityValid(
|
const remoteCopied = ensureMTimeOfRemoteEntityValid(
|
||||||
await decryptRemoteEntityInplace(
|
await decryptRemoteEntityInplace(
|
||||||
copyEntityAndFixTimeFormat(remote),
|
copyEntityAndFixTimeFormat(remote, serviceType),
|
||||||
password
|
password
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -418,14 +435,14 @@ export const ensembleMixedEnties = async (
|
|||||||
|
|
||||||
if (finalMappings.hasOwnProperty(key)) {
|
if (finalMappings.hasOwnProperty(key)) {
|
||||||
const prevSyncCopied = await encryptLocalEntityInplace(
|
const prevSyncCopied = await encryptLocalEntityInplace(
|
||||||
copyEntityAndFixTimeFormat(prevSync),
|
copyEntityAndFixTimeFormat(prevSync, serviceType),
|
||||||
password,
|
password,
|
||||||
finalMappings[key].remote?.keyEnc
|
finalMappings[key].remote?.keyEnc
|
||||||
);
|
);
|
||||||
finalMappings[key].prevSync = prevSyncCopied;
|
finalMappings[key].prevSync = prevSyncCopied;
|
||||||
} else {
|
} else {
|
||||||
const prevSyncCopied = await encryptLocalEntityInplace(
|
const prevSyncCopied = await encryptLocalEntityInplace(
|
||||||
copyEntityAndFixTimeFormat(prevSync),
|
copyEntityAndFixTimeFormat(prevSync, serviceType),
|
||||||
password,
|
password,
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
@ -456,14 +473,14 @@ export const ensembleMixedEnties = async (
|
|||||||
|
|
||||||
if (finalMappings.hasOwnProperty(key)) {
|
if (finalMappings.hasOwnProperty(key)) {
|
||||||
const localCopied = await encryptLocalEntityInplace(
|
const localCopied = await encryptLocalEntityInplace(
|
||||||
copyEntityAndFixTimeFormat(local),
|
copyEntityAndFixTimeFormat(local, serviceType),
|
||||||
password,
|
password,
|
||||||
finalMappings[key].remote?.keyEnc
|
finalMappings[key].remote?.keyEnc
|
||||||
);
|
);
|
||||||
finalMappings[key].local = localCopied;
|
finalMappings[key].local = localCopied;
|
||||||
} else {
|
} else {
|
||||||
const localCopied = await encryptLocalEntityInplace(
|
const localCopied = await encryptLocalEntityInplace(
|
||||||
copyEntityAndFixTimeFormat(local),
|
copyEntityAndFixTimeFormat(local, serviceType),
|
||||||
password,
|
password,
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user