Use .tmp before the file extension (#529)

When creating temporary files use the pattern `.tmp.ext` instead of
`.ext.tmp` to be consistent with Factorio which creates `.tmp.zip` files
during saving.

If patching fails this will leave a `.tmp.zip` file in the instance saves
directory which is ignored by the default save selector.

Resolves #486.
This commit is contained in:
Hornwitser authored and GitHub committed 2023-11-30 01:21:06 +01:00
1 parent faadf873fb
commit d5bcd34cdb
6 files changed
+28 -12

No files matched your search

+16 -2
View File
@@ -88,16 +88,30 @@ describe("lib/file_ops", function() {
it("should write new target file", async function() {
let target = path.join(baseDir, "safe", "simple.txt");
await lib.safeOutputFile(target, "a text file", "utf8");
assert(!await fs.pathExists(`${target}.tmp`), "temporary was left behind");
assert(!await fs.pathExists(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
assert.equal(await fs.readFile(target, "utf8"), "a text file");
});
it("should overwrite existing target file", async function() {
let target = path.join(baseDir, "safe", "exists.txt");
await fs.outputFile(target, "previous", "utf8");
await lib.safeOutputFile(target, "current", "utf8");
assert(!await fs.pathExists(`${target}.tmp`), "temporary was left behind");
assert(!await fs.pathExists(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
assert.equal(await fs.readFile(target, "utf8"), "current");
});
it("should handle creating file in current working directory", async function() {
let target = "temporary-file-made-to-test-cwd.txt";
try {
await lib.safeOutputFile(target, "a text file", "utf8");
} finally {
try {
await fs.unlink(target);
} catch (err) {
if (err.code !== "ENOENT") {
throw err;
}
}
}
});
});
describe("checkFilename()", function() {