feat: add fallback mechanism when fs.rename is unsupported (#272)

This commit is contained in:
Daniel Stefani
2025-10-02 15:01:06 +02:00
committed by GitHub
parent 6b979a22fb
commit 6086d2a0ac

View File

@@ -240,7 +240,7 @@ export class FilesystemStorageProvider implements StorageProvider {
try { try {
await pipeline(inputStream, encryptStream, writeStream); await pipeline(inputStream, encryptStream, writeStream);
await fs.rename(tempPath, filePath); await this.moveFile(tempPath, filePath);
} catch (error) { } catch (error) {
await this.cleanupTempFile(tempPath); await this.cleanupTempFile(tempPath);
throw error; throw error;
@@ -707,4 +707,18 @@ export class FilesystemStorageProvider implements StorageProvider {
console.error("Error during temp directory cleanup:", error); console.error("Error during temp directory cleanup:", error);
} }
} }
private async moveFile(src: string, dest: string): Promise<void> {
try {
await fs.rename(src, dest);
} catch (err: any) {
if (err.code === "EXDEV") {
// cross-device: fallback to copy + delete
await fs.copyFile(src, dest);
await fs.unlink(src);
} else {
throw err;
}
}
}
} }