mirror of
https://github.com/kyantech/Palmr.git
synced 2025-10-23 06:11:58 +00:00
feat: add fallback mechanism when fs.rename is unsupported (#272)
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user