From 6226a45d0b59514664c4a77cac5a3375d72d4338 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 4 Sep 2024 00:14:47 +0200 Subject: [PATCH] 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. --- packages/lib/src/file_ops.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lib/src/file_ops.ts b/packages/lib/src/file_ops.ts index 5cd44961..95d30714 100644 --- a/packages/lib/src/file_ops.ts +++ b/packages/lib/src/file_ops.ts @@ -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);