Skip to content

Commit

Permalink
Different profile directory name in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Feb 15, 2024
1 parent e6f152e commit 41a2354
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 24 additions & 1 deletion __test__/backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 41a2354

Please sign in to comment.