From 41a2354bee566874ac33f1b3e0bf741dd35667b0 Mon Sep 17 00:00:00 2001 From: Henry H Date: Wed, 14 Feb 2024 22:40:12 -0800 Subject: [PATCH] Different profile directory name in dev mode --- __test__/backup.test.ts | 25 ++++++++++++++++++++++++- src/Backup.ts | 6 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/__test__/backup.test.ts b/__test__/backup.test.ts index b6005c8..781be57 100644 --- a/__test__/backup.test.ts +++ b/__test__/backup.test.ts @@ -187,21 +187,41 @@ describe("Backup", function () { { rootProfileDir: testPath.joplinProfile, profileDir: testPath.joplinProfile, + joplinEnv: "prod", expectedProfileName: "default", }, + { + rootProfileDir: testPath.joplinProfile, + profileDir: testPath.joplinProfile, + joplinEnv: "dev", + expectedProfileName: "default-dev", + }, { rootProfileDir: testPath.joplinProfile, profileDir: path.join(testPath.joplinProfile, "profile-test"), + joplinEnv: "prod", expectedProfileName: "profile-test", }, { rootProfileDir: testPath.joplinProfile, profileDir: path.join(testPath.joplinProfile, "profile-idhere"), + joplinEnv: "prod", expectedProfileName: "profile-idhere", }, + { + rootProfileDir: testPath.joplinProfile, + profileDir: path.join(testPath.joplinProfile, "profile-idhere"), + joplinEnv: "dev", + expectedProfileName: "profile-idhere-dev", + }, ])( "should correctly set backupBasePath based on the current profile name (case %#)", - async ({ profileDir, rootProfileDir, expectedProfileName }) => { + async ({ + profileDir, + rootProfileDir, + joplinEnv, + expectedProfileName, + }) => { when(spyOnsSettingsValue) .calledWith("path") .mockImplementation(async () => testPath.backupBasePath); @@ -211,6 +231,9 @@ describe("Backup", function () { when(spyOnGlobalValue) .calledWith("profileDir") .mockImplementation(async () => profileDir); + when(spyOnGlobalValue) + .calledWith("env") + .mockImplementation(async () => joplinEnv); // Should use the folder named "default" for the default profile backup.createSubfolderPerProfile = true; diff --git a/src/Backup.ts b/src/Backup.ts index bf2a415..6b411a7 100644 --- a/src/Backup.ts +++ b/src/Backup.ts @@ -312,6 +312,12 @@ class Backup { profileName = "default"; } + // This prevents the default joplin-dev profile's backup from overwriting + // a non-dev profile (both have a default profile named "default"). + if ((await joplin.settings.globalValue("env")) === "dev") { + profileName += "-dev"; + } + this.backupBasePath = path.join(this.backupBasePath, profileName); await handleSubfolderCreation(); }