Skip to content

Commit 5de4449

Browse files
authored
Merge pull request #293 from mook-as/win-log-clobber
Logging: Only delete files if we have single instance lock
2 parents 695736f + f167780 commit 5de4449

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/utils/logging.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import fs from 'fs';
1717
import path from 'path';
1818
import stream from 'stream';
1919

20+
import Electron from 'electron';
2021
import XDGAppPaths from 'xdg-app-paths';
2122
const paths = XDGAppPaths({ name: 'rancher-desktop' });
2223
const logDir = path.join(paths.runtime() || paths.state(), 'logs');
@@ -110,13 +111,19 @@ export default new Proxy(logging, {
110111
* main process, and due to how imports work, only ever called once.
111112
* Unforunately, this must be done synchronously to avoid deleting log files
112113
* that are newly created.
114+
*
115+
* This is only done if we have the electron single-instance lock, as we do not
116+
* want to delete logs for existing instances - this should not be an issue, as
117+
* we will quit shortly.
113118
*/
114119
// The main process is 'browser', as opposed to 'renderer'.
115120
if (process.type === 'browser') {
116-
fs.mkdirSync(logDir, { recursive: true });
117-
for (const entry of fs.readdirSync(logDir, { withFileTypes: true })) {
118-
if (entry.isFile() && entry.name.endsWith('.log')) {
119-
fs.unlinkSync(path.join(logDir, entry.name));
121+
if (Electron.app.requestSingleInstanceLock()) {
122+
fs.mkdirSync(logDir, { recursive: true });
123+
for (const entry of fs.readdirSync(logDir, { withFileTypes: true })) {
124+
if (entry.isFile() && entry.name.endsWith('.log')) {
125+
fs.unlinkSync(path.join(logDir, entry.name));
126+
}
120127
}
121128
}
122129
}

0 commit comments

Comments
 (0)