Skip to content

Commit aabdcea

Browse files
committed
Await rimraf promise
1 parent 2d9ce31 commit aabdcea

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

public/core/ipfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = async (ipc) => {
4242
const apiLockFile = path.join(settings.ROOT_IPFS_DIR, 'api')
4343
if (fs.existsSync(apiLockFile)) {
4444
log.warn('Removing old `api` file');
45-
removeFiles(apiLockFile)
45+
await removeFiles(apiLockFile)
4646
}
4747

4848
// Check if running time dir exists

public/core/utils.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ const log = require('electron-log');
22
const rimraf = require('rimraf');
33

44
module.exports.removeFiles = (dirOrFIle, options) => {
5-
rimraf(dirOrFIle, {
6-
...{
7-
disableGlob: true,
8-
maxBusyTries: 20,
9-
emfileWait: 10 * 1000
10-
}, ...options
11-
}, () => {
12-
log.warn('Delete file ' + dirOrFIle);
13-
});
5+
return new Promise((resolve) => {
6+
rimraf(dirOrFIle, {
7+
...{
8+
disableGlob: true,
9+
maxBusyTries: 20,
10+
emfileWait: 10 * 1000
11+
}, ...options
12+
}, () => {
13+
log.warn('Delete file ' + dirOrFIle);
14+
resolve()
15+
});
16+
})
1417
}

public/electron.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const removeCacheDirs = () => {
3838
//Auth.removeFromStorage('tmp')
3939
fs.readdirSync(appPath).filter(
4040
fn => fn.startsWith('w_alloc') || fn.startsWith('w_source')
41-
).forEach((file) => {
41+
).forEach(async (file) => {
4242
log.warn('Removing ' + file);
43-
removeFiles(path.join(appPath, file))
43+
await removeFiles(path.join(appPath, file))
4444
});
4545
}, wipeInvalidSync = () => {
4646
Auth.removeFromStorage('peers')
@@ -50,11 +50,11 @@ const removeCacheDirs = () => {
5050
}
5151
}, wipeTmpSubs = () => {
5252
//Loop over files in dir
53-
fs.readdir(ROOT_TMP_FOLDER, (err, files) => {
53+
fs.readdir(ROOT_TMP_FOLDER, async (err, files) => {
5454
if (!files || !files.length) return false;
5555
for (const file of files) {
5656
if (/(srt|vtt|zip)$/g.test(file)) {
57-
removeFiles(path.join(ROOT_TMP_FOLDER, file));
57+
await removeFiles(path.join(ROOT_TMP_FOLDER, file));
5858
}
5959
}
6060
})
@@ -279,13 +279,12 @@ app.whenReady().then(() => {
279279
Orbit(ipcMain);
280280

281281
// Window event
282-
ipcMain.on('rmrf', (dir) => {
283-
removeFiles(dir)
284-
})
282+
285283

286284
ipcMain.on('close', () => app.quit())
287-
ipcMain.on('party', () => {
288-
if (Auth.existKey) removeFiles(Auth.keyFile)
285+
ipcMain.on('party', async () => {
286+
if (Auth.existKey)
287+
await removeFiles(Auth.keyFile)
289288
removeCacheDirs();
290289
})
291290

0 commit comments

Comments
 (0)