Skip to content

Commit

Permalink
Await rimraf promise
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Jan 28, 2021
1 parent 2d9ce31 commit aabdcea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion public/core/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = async (ipc) => {
const apiLockFile = path.join(settings.ROOT_IPFS_DIR, 'api')
if (fs.existsSync(apiLockFile)) {
log.warn('Removing old `api` file');
removeFiles(apiLockFile)
await removeFiles(apiLockFile)
}

// Check if running time dir exists
Expand Down
21 changes: 12 additions & 9 deletions public/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ const log = require('electron-log');
const rimraf = require('rimraf');

module.exports.removeFiles = (dirOrFIle, options) => {
rimraf(dirOrFIle, {
...{
disableGlob: true,
maxBusyTries: 20,
emfileWait: 10 * 1000
}, ...options
}, () => {
log.warn('Delete file ' + dirOrFIle);
});
return new Promise((resolve) => {
rimraf(dirOrFIle, {
...{
disableGlob: true,
maxBusyTries: 20,
emfileWait: 10 * 1000
}, ...options
}, () => {
log.warn('Delete file ' + dirOrFIle);
resolve()
});
})
}
17 changes: 8 additions & 9 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const removeCacheDirs = () => {
//Auth.removeFromStorage('tmp')
fs.readdirSync(appPath).filter(
fn => fn.startsWith('w_alloc') || fn.startsWith('w_source')
).forEach((file) => {
).forEach(async (file) => {
log.warn('Removing ' + file);
removeFiles(path.join(appPath, file))
await removeFiles(path.join(appPath, file))
});
}, wipeInvalidSync = () => {
Auth.removeFromStorage('peers')
Expand All @@ -50,11 +50,11 @@ const removeCacheDirs = () => {
}
}, wipeTmpSubs = () => {
//Loop over files in dir
fs.readdir(ROOT_TMP_FOLDER, (err, files) => {
fs.readdir(ROOT_TMP_FOLDER, async (err, files) => {
if (!files || !files.length) return false;
for (const file of files) {
if (/(srt|vtt|zip)$/g.test(file)) {
removeFiles(path.join(ROOT_TMP_FOLDER, file));
await removeFiles(path.join(ROOT_TMP_FOLDER, file));
}
}
})
Expand Down Expand Up @@ -279,13 +279,12 @@ app.whenReady().then(() => {
Orbit(ipcMain);

// Window event
ipcMain.on('rmrf', (dir) => {
removeFiles(dir)
})


ipcMain.on('close', () => app.quit())
ipcMain.on('party', () => {
if (Auth.existKey) removeFiles(Auth.keyFile)
ipcMain.on('party', async () => {
if (Auth.existKey)
await removeFiles(Auth.keyFile)
removeCacheDirs();
})

Expand Down

0 comments on commit aabdcea

Please sign in to comment.