mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
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:
1 parent
faadf873fb
commit
d5bcd34cdb
6 files changed
+28
-12
No files matched your search
@@ -126,7 +126,8 @@ export async function getTempFile(prefix = "tmp.", suffix = "", tmpdir = "./") {
|
||||
*
|
||||
* Same as fs-extra.outputFile except the data is written to a temporary
|
||||
* file that's renamed over the target file. The name of the temporary file
|
||||
* is the same as the target file with the suffix `.tmp` added.
|
||||
* is the same as the target file with the suffix `.tmp` added before the
|
||||
* extension.
|
||||
*
|
||||
* If the operation fails it may leave behind the temporary file. This
|
||||
* should not be too much of an issue as the next time the same file is
|
||||
@@ -137,11 +138,11 @@ export async function getTempFile(prefix = "tmp.", suffix = "", tmpdir = "./") {
|
||||
* @param options - see fs.writeFile, `flag` must not be set.
|
||||
*/
|
||||
export async function safeOutputFile(file: string, data: string | Buffer, options: fs.WriteFileOptions ={}) {
|
||||
let directory = path.dirname(file);
|
||||
if (!await fs.pathExists(directory)) {
|
||||
await fs.mkdirs(directory);
|
||||
let { dir, name, ext } = path.parse(file);
|
||||
if (dir && !await fs.pathExists(dir)) {
|
||||
await fs.mkdirs(dir);
|
||||
}
|
||||
let temporary = `${file}.tmp`;
|
||||
let temporary = `${dir}${name}.tmp${ext}`;
|
||||
let fd = await fs.open(temporary, "w");
|
||||
try {
|
||||
await fs.writeFile(fd, data, options);
|
||||
|
||||
Reference in new issue
Block a user