joplin-plugin-backup 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Build and test
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
buildAndTest:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
steps:
|
|
7
|
+
- uses: actions/checkout@v2
|
|
8
|
+
- uses: actions/setup-node@v2
|
|
9
|
+
with:
|
|
10
|
+
node-version: "16"
|
|
11
|
+
- name: Install dependencies
|
|
12
|
+
run: npm install
|
|
13
|
+
- name: Build
|
|
14
|
+
run: npm run dist
|
|
15
|
+
- name: Run test
|
|
16
|
+
run: npm test
|
package/.husky/pre-push
CHANGED
package/__test__/backup.test.ts
CHANGED
|
@@ -298,6 +298,51 @@ describe("Backup", function () {
|
|
|
298
298
|
expect(fs.existsSync(expected)).toBe(true);
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
+
it(`retention = 1, folder exist with same files and folder`, async () => {
|
|
302
|
+
const emptyFolder = path.join(testPath.activeBackupJob, "emptyFolder");
|
|
303
|
+
const emptyFolderCheck = path.join(
|
|
304
|
+
testPath.backupBasePath,
|
|
305
|
+
"emptyFolder"
|
|
306
|
+
);
|
|
307
|
+
const folderNotes = path.join(testPath.activeBackupJob, "notes");
|
|
308
|
+
const folderNotesCheck = path.join(testPath.backupBasePath, "notes");
|
|
309
|
+
const file1 = path.join(folderNotes, "file.txt");
|
|
310
|
+
const file1Check = path.join(folderNotesCheck, "file.txt");
|
|
311
|
+
const file2 = path.join(testPath.activeBackupJob, "file.txt");
|
|
312
|
+
const file2Check = path.join(testPath.backupBasePath, "file.txt");
|
|
313
|
+
const file3Check = path.join(testPath.backupBasePath, "fileStay.txt");
|
|
314
|
+
const file4Check = path.join(folderNotesCheck, "fileNo.txt");
|
|
315
|
+
backup.backupBasePath = testPath.backupBasePath;
|
|
316
|
+
backup.activeBackupPath = testPath.activeBackupJob;
|
|
317
|
+
|
|
318
|
+
fs.emptyDirSync(testPath.backupBasePath);
|
|
319
|
+
fs.emptyDirSync(emptyFolderCheck);
|
|
320
|
+
fs.emptyDirSync(folderNotesCheck);
|
|
321
|
+
fs.writeFileSync(file1Check, "old file");
|
|
322
|
+
fs.writeFileSync(file2Check, "old file");
|
|
323
|
+
fs.writeFileSync(file3Check, "old file");
|
|
324
|
+
fs.writeFileSync(file4Check, "old file");
|
|
325
|
+
|
|
326
|
+
fs.emptyDirSync(testPath.activeBackupJob);
|
|
327
|
+
fs.emptyDirSync(emptyFolder);
|
|
328
|
+
fs.emptyDirSync(folderNotes);
|
|
329
|
+
fs.writeFileSync(file1, "new file");
|
|
330
|
+
fs.writeFileSync(file2, "new file");
|
|
331
|
+
|
|
332
|
+
backup.backupRetention = 1;
|
|
333
|
+
|
|
334
|
+
expect(await backup.moveFinishedBackup()).toBe(testPath.backupBasePath);
|
|
335
|
+
expect(fs.existsSync(folderNotes)).toBe(false);
|
|
336
|
+
expect(fs.existsSync(folderNotesCheck)).toBe(true);
|
|
337
|
+
expect(fs.existsSync(emptyFolderCheck)).toBe(true);
|
|
338
|
+
expect(fs.existsSync(file1Check)).toBe(true);
|
|
339
|
+
expect(fs.existsSync(file2Check)).toBe(true);
|
|
340
|
+
expect(fs.existsSync(file3Check)).toBe(true);
|
|
341
|
+
expect(fs.existsSync(file4Check)).toBe(false);
|
|
342
|
+
expect(backup.log.error).toHaveBeenCalledTimes(0);
|
|
343
|
+
expect(backup.log.warn).toHaveBeenCalledTimes(0);
|
|
344
|
+
});
|
|
345
|
+
|
|
301
346
|
it(`retention > 1, file exist`, async () => {
|
|
302
347
|
backup.backupBasePath = testPath.backupBasePath;
|
|
303
348
|
backup.activeBackupPath = testPath.activeBackupJob;
|
|
@@ -483,9 +528,9 @@ describe("Backup", function () {
|
|
|
483
528
|
backupRetention: 1,
|
|
484
529
|
password: null,
|
|
485
530
|
singleJex: true,
|
|
486
|
-
result: path.join(testPath.backupBasePath
|
|
531
|
+
result: path.join(testPath.backupBasePath),
|
|
487
532
|
testFile: "testFile.txt",
|
|
488
|
-
checkFile: path.join(testPath.backupBasePath, "
|
|
533
|
+
checkFile: path.join(testPath.backupBasePath, "testFile.txt.7z"),
|
|
489
534
|
saveBackupInfoCalled: 0,
|
|
490
535
|
},
|
|
491
536
|
{
|
|
@@ -493,9 +538,13 @@ describe("Backup", function () {
|
|
|
493
538
|
backupRetention: 2,
|
|
494
539
|
password: null,
|
|
495
540
|
singleJex: true,
|
|
496
|
-
result: path.join(testPath.backupBasePath, "202101021630
|
|
541
|
+
result: path.join(testPath.backupBasePath, "202101021630"),
|
|
497
542
|
testFile: "testFile.txt",
|
|
498
|
-
checkFile: path.join(
|
|
543
|
+
checkFile: path.join(
|
|
544
|
+
testPath.backupBasePath,
|
|
545
|
+
"202101021630",
|
|
546
|
+
"testFile.txt.7z"
|
|
547
|
+
),
|
|
499
548
|
saveBackupInfoCalled: 1,
|
|
500
549
|
},
|
|
501
550
|
{
|
|
@@ -756,86 +805,104 @@ describe("Backup", function () {
|
|
|
756
805
|
expect(backup.log.transports.file.level).toBe("error");
|
|
757
806
|
});
|
|
758
807
|
|
|
759
|
-
|
|
808
|
+
describe("move logfile", function () {
|
|
760
809
|
const testCases = [
|
|
761
810
|
{
|
|
811
|
+
description: "backupBasePath",
|
|
762
812
|
zipArchive: "no",
|
|
763
813
|
password: null,
|
|
764
814
|
logDst: testPath.backupBasePath,
|
|
765
|
-
testLogFile: path.join(testPath.backupBasePath, "backup.log"),
|
|
766
815
|
},
|
|
767
816
|
{
|
|
817
|
+
description: "backupBasePath, password",
|
|
768
818
|
zipArchive: "no",
|
|
769
|
-
password:
|
|
770
|
-
logDst:
|
|
771
|
-
testLogFile: path.join(
|
|
772
|
-
testPath.backupBasePath,
|
|
773
|
-
"testDir",
|
|
774
|
-
"backup.log"
|
|
775
|
-
),
|
|
819
|
+
password: "secret",
|
|
820
|
+
logDst: testPath.backupBasePath,
|
|
776
821
|
},
|
|
777
822
|
{
|
|
823
|
+
description: "backupBasePath, zip, password",
|
|
778
824
|
zipArchive: "yes",
|
|
779
|
-
password:
|
|
780
|
-
logDst:
|
|
781
|
-
testLogFile: path.join(
|
|
782
|
-
testPath.backupBasePath,
|
|
783
|
-
"testDir",
|
|
784
|
-
"backup.log"
|
|
785
|
-
),
|
|
825
|
+
password: "secret",
|
|
826
|
+
logDst: testPath.backupBasePath,
|
|
786
827
|
},
|
|
787
828
|
{
|
|
829
|
+
description: "backupBasePath, zip one",
|
|
788
830
|
zipArchive: "yesone",
|
|
789
831
|
password: null,
|
|
790
|
-
logDst: path.join(testPath.backupBasePath, "
|
|
791
|
-
testLogFile: "backup.log",
|
|
832
|
+
logDst: path.join(testPath.backupBasePath, "retention.7z"),
|
|
792
833
|
},
|
|
793
834
|
{
|
|
835
|
+
description: "backupBasePath, zip one, password",
|
|
794
836
|
zipArchive: "yesone",
|
|
795
837
|
password: "secret",
|
|
796
|
-
logDst: path.join(testPath.backupBasePath, "
|
|
797
|
-
|
|
838
|
+
logDst: path.join(testPath.backupBasePath, "retention.7z"),
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
description: "sub in backupBasePath",
|
|
842
|
+
zipArchive: "no",
|
|
843
|
+
password: null,
|
|
844
|
+
logDst: path.join(testPath.backupBasePath, "retentionfolder"),
|
|
798
845
|
},
|
|
799
846
|
{
|
|
847
|
+
description: "sub in backupBasePath, password",
|
|
800
848
|
zipArchive: "no",
|
|
801
849
|
password: "secret",
|
|
802
|
-
logDst: testPath.backupBasePath,
|
|
803
|
-
|
|
850
|
+
logDst: path.join(testPath.backupBasePath, "retentionfolder"),
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
description: "sub in backupBasePath, zip",
|
|
854
|
+
zipArchive: "yes",
|
|
855
|
+
password: null,
|
|
856
|
+
logDst: path.join(testPath.backupBasePath, "retentionfolder"),
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
description: "sub in backupBasePath, password, zip",
|
|
860
|
+
zipArchive: "yes",
|
|
861
|
+
password: "secret",
|
|
862
|
+
logDst: path.join(testPath.backupBasePath, "retentionfolder"),
|
|
804
863
|
},
|
|
805
864
|
];
|
|
806
865
|
|
|
807
|
-
backup.logFile = path.join(testPath.base, "test.log");
|
|
808
866
|
for (const testCase of testCases) {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
867
|
+
it(`${testCase.description}`, async () => {
|
|
868
|
+
backup.logFile = path.join(testPath.base, "test.log");
|
|
869
|
+
backup.zipArchive = testCase.zipArchive;
|
|
870
|
+
backup.password = testCase.password;
|
|
871
|
+
|
|
872
|
+
await createTestStructure();
|
|
873
|
+
|
|
874
|
+
if (testCase.zipArchive === "yesone") {
|
|
875
|
+
const dummyFile = path.join(testPath.base, "dummy");
|
|
876
|
+
fs.writeFileSync(dummyFile, "dummy");
|
|
877
|
+
expect(fs.existsSync(dummyFile)).toBe(true);
|
|
878
|
+
await sevenZip.add(testCase.logDst, dummyFile, testCase.password);
|
|
879
|
+
expect(fs.existsSync(testCase.logDst)).toBe(true);
|
|
880
|
+
} else {
|
|
881
|
+
fs.emptyDirSync(testCase.logDst);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
fs.writeFileSync(backup.logFile, "log");
|
|
885
|
+
expect(fs.existsSync(backup.logFile)).toBe(true);
|
|
886
|
+
|
|
887
|
+
expect(await backup.moveLogFile(testCase.logDst)).toBe(true);
|
|
888
|
+
expect(fs.existsSync(backup.logFile)).toBe(false);
|
|
889
|
+
|
|
890
|
+
let checkBackupLogFile = path.join(testCase.logDst, "backup.log");
|
|
891
|
+
if (testCase.zipArchive === "yesone") {
|
|
892
|
+
checkBackupLogFile = testCase.logDst;
|
|
893
|
+
} else if (testCase.password !== null) {
|
|
894
|
+
checkBackupLogFile = path.join(testCase.logDst, "backuplog.7z");
|
|
895
|
+
}
|
|
896
|
+
expect(fs.existsSync(checkBackupLogFile)).toBe(true);
|
|
897
|
+
|
|
898
|
+
if (testCase.password !== null || testCase.zipArchive === "yesone") {
|
|
899
|
+
const fileList = await sevenZip.list(
|
|
900
|
+
testCase.logDst,
|
|
901
|
+
testCase.password
|
|
902
|
+
);
|
|
903
|
+
expect(fileList.map((f) => f.file)).toContain("backup.log");
|
|
904
|
+
}
|
|
905
|
+
});
|
|
839
906
|
}
|
|
840
907
|
});
|
|
841
908
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joplin-plugin-backup",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
|
6
6
|
"prepare": "npm run dist && husky install",
|
|
Binary file
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": 1,
|
|
3
3
|
"id": "io.github.jackgruber.backup",
|
|
4
4
|
"app_min_version": "2.1.3",
|
|
5
|
-
"version": "1.2.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"name": "Simple Backup",
|
|
7
7
|
"description": "Plugin to create manual and automatic backups.",
|
|
8
8
|
"author": "JackGruber",
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
"7zip",
|
|
17
17
|
"encrypted"
|
|
18
18
|
],
|
|
19
|
-
"_publish_hash": "sha256:
|
|
20
|
-
"_publish_commit": "master:
|
|
19
|
+
"_publish_hash": "sha256:ddc31c99405ef7aaa001b1dca7f52f57723975f8a7cdc2fc6f99f08c0ae0b6fb",
|
|
20
|
+
"_publish_commit": "master:84f2205b58043113c39f09d9c253bba260a11331"
|
|
21
21
|
}
|