Dockersafe rename (#1370)

* add dockerSafeRename function

* replace all rename functions

* add explanation to function
This commit is contained in:
Alex Christoffer Rasmussen
2024-12-10 23:27:51 +01:00
committed by GitHub
parent 7dbf64d100
commit 7915cc822d
3 changed files with 25 additions and 10 deletions
+11 -2
View File
@@ -1,5 +1,5 @@
import { existsSync, mkdirSync } from 'fs';
import { readdir, copyFile } from 'fs/promises';
import { existsSync, mkdirSync, PathLike } from 'fs';
import { readdir, copyFile, unlink } from 'fs/promises';
import { basename, extname, join, parse } from 'path';
/**
@@ -105,3 +105,12 @@ export async function copyDirectory(src: string, dest: string) {
}
}
}
/**
* workaround avoids origin errors in docker deployments
* EXDEV cross-device link not permitted
*/
export async function dockerSafeRename(oldPath: PathLike, newPath: PathLike) {
await copyFile(oldPath, newPath);
await unlink(oldPath);
}