同步处理

This commit is contained in:
tianmo committed 2026-10-17 18:15:42 +08:00
1 parent 9939943e31
commit 6494ad2918
26 files changed
+970 -40

No files matched your search

+24
View File
@@ -151,3 +151,27 @@ export async function cleanupLocalAtomicTempFiles(
}
return removed
}
/** Move an already-complete file into the storage tree without loading it into memory. */
export async function putLocalFileAtomic(
key: string,
sourcePath: string
): Promise<void> {
const filePath = keyToFilePath(key)
await fs.mkdir(dirname(filePath), { recursive: true })
try {
await fs.rename(sourcePath, filePath)
} catch (error) {
if (
error
&& typeof error === 'object'
&& 'code' in error
&& error.code === 'EXDEV'
) {
await fs.copyFile(sourcePath, filePath)
await fs.rm(sourcePath, { force: true })
return
}
throw error
}
}