Skip to content

Commit

Permalink
fix: Fixed force backup on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed Jul 1, 2021
1 parent 005bb0b commit ba01abd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/backup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import * as Path from 'path';
import { app, ipcMain, WebContents } from 'electron';
import dateFormat from 'dateformat';
import * as BackupIPC from './constants/BackupIPC';

export default class Backup {
Expand Down Expand Up @@ -63,7 +64,10 @@ export default class Backup {
const fileName =
this.iteration >= 0
? `${Path.basename(this.path)}.bak${this.iteration + 1}`
: `${Path.basename(this.path)}.bak${new Date().toISOString()}`;
: `${Path.basename(this.path)}.bak${dateFormat(
new Date(),
'yyyymmddHHMMss'
)}`;
const dest = Path.join(Backup.backupDir, fileName);

try {
Expand Down Expand Up @@ -96,7 +100,9 @@ export default class Backup {
const path = Path.join(Backup.backupDir, p);
if (fs.existsSync(path)) {
const stats = fs.statSync(path);
const date = new Date(stats.mtimeMs);
const date = new Date(
process.platform === 'win32' ? stats.atimeMs : stats.mtimeMs
);
const now = new Date();
const diff = now.getTime() - date.getTime();
if (diff >= this.retention) {
Expand Down
4 changes: 3 additions & 1 deletion app/menu/FileMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const buildFileMenu = (
path
);
const stats = fs.statSync(fullPath);
const date = new Date(stats.mtimeMs);
const date = new Date(
process.platform === 'win32' ? stats.atimeMs : stats.mtimeMs
);
return { path, date };
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"archiver": "^5.0.2",
"chardet": "^1.3.0",
"connected-react-router": "^6.6.1",
"dateformat": "^4.5.1",
"deep-equal": "^2.0.4",
"electron-debug": "^3.1.0",
"electron-log": "^4.2.4",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4704,6 +4704,11 @@ date-fns@^2.0.1:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.16.1.tgz#05775792c3f3331da812af253e1a935851d3834b"
integrity sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==

dateformat@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.5.1.tgz#c20e7a9ca77d147906b6dc2261a8be0a5bd2173c"
integrity sha512-OD0TZ+B7yP7ZgpJf5K2DIbj3FZvFvxgFUuaqA/V5zTjAtAAXZ1E8bktHxmAGs4x5b7PflqA9LeQ84Og7wYtF7Q==

debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.5.1, debug@^2.6.0, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down

0 comments on commit ba01abd

Please sign in to comment.