Fix safeOutputFile writing to wrong directory (#659)

When renaming a file over another file the operation is only atomic if
both the source file and the target file is in the same directory.  Fix
safeOutputFile writing the temporary file to a different directory than
the target file due to the path separator not being included when
creating the temporary file path.
This commit is contained in:
Hornwitser authored and GitHub committed 2024-09-04 00:14:47 +02:00
1 parent 84958e3f9d
commit 6226a45d0b
1 file changed
+1 -1
+1 -1
View File
@@ -142,7 +142,7 @@ export async function safeOutputFile(file: string, data: string | Buffer, option
if (dir && !await fs.pathExists(dir)) {
await fs.mkdirs(dir);
}
let temporary = `${dir}${name}.tmp${ext}`;
let temporary = path.join(dir, `${name}.tmp${ext}`);
let fd = await fs.open(temporary, "w");
try {
await fs.writeFile(fd, data, options);