diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 0239d27..42f021d 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -83,13 +83,20 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar try { //create file write stream const outputName = path.join(targetDir, file.name); - await createDirRecursively(path.dirname(outputName)); - const outputStream = fs.createWriteStream(outputName); + const outputNameTemp = path.join(targetDir, `${file.name}.tmp`); + await createDirRecursively(path.dirname(outputNameTemp)); + const outputStream = fs.createWriteStream(outputNameTemp); //start installation await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, undefined, outputStream); outputStream.close(); + + fs.rename(outputNameTemp, outputName, (renameError) => { + if (renameError) { + throw new Error(`Could not rename output file "${outputNameTemp}": ${renameError.name}`); + } + }); } catch (error) { console.error(`Could not extract file "${file.name}"`, error); }