mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
Copy save if the save to start is an autosave
Prevent potential data loss when starting an autosave by copying it first. This avoids overwriting a random autosave slot when the server shuts down after having loaded an autosave.
This commit is contained in:
1 parent
12db0d5a84
commit
a0f5864324
2 files changed
+29
-2
No files matched your search
@@ -461,6 +461,23 @@ class Instance extends libLink.Link {
|
||||
saveName = "world.zip";
|
||||
}
|
||||
|
||||
// Load a copy if it's autosave to prevent overwriting the autosave
|
||||
if (saveName.startsWith("_autosave")) {
|
||||
this.logger.info("Copying autosave");
|
||||
let now = new Date();
|
||||
let newName = util.format(
|
||||
"%s-%s-%s %s%s %s",
|
||||
now.getUTCFullYear(),
|
||||
(now.getUTCMonth() + 1).toLocaleString("en", { minimumIntegerDigits: 2 }),
|
||||
now.getUTCDate().toLocaleString("en", { minimumIntegerDigits: 2 }),
|
||||
now.getUTCHours().toLocaleString("en", { minimumIntegerDigits: 2 }),
|
||||
now.getUTCMinutes().toLocaleString("en", { minimumIntegerDigits: 2 }),
|
||||
saveName,
|
||||
);
|
||||
await fs.copy(this.path("saves", saveName), this.path("saves", newName));
|
||||
saveName = newName;
|
||||
}
|
||||
|
||||
if (!this.config.get("factorio.enable_save_patching")) {
|
||||
return saveName;
|
||||
}
|
||||
|
||||
@@ -173,11 +173,21 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
|
||||
describe("instance start", function() {
|
||||
it("starts the instance", async function() {
|
||||
it("starts the given save", async function() {
|
||||
slowTest(this);
|
||||
await execCtl("instance start test");
|
||||
await execCtl("instance start test --save world.zip");
|
||||
await checkInstanceStatus(44, "running");
|
||||
});
|
||||
it("copies the save if an autosave is the target", async function() {
|
||||
slowTest(this);
|
||||
await execCtl("instance stop 44");
|
||||
let savesDir = path.join("temp", "test", "instances", "test", "saves");
|
||||
await fs.copy(path.join(savesDir, "world.zip"), path.join(savesDir, "_autosave1.zip"));
|
||||
await execCtl("instance start test");
|
||||
let result = await libLink.messages.listSaves.send(getControl(), { instance_id: 44 });
|
||||
let running = result.list.find(s => s.loaded);
|
||||
assert(running.name !== "_autosave1.zip");
|
||||
});
|
||||
});
|
||||
|
||||
describe("instance send-rcon", function() {
|
||||
|
||||
Reference in new issue
Block a user