Skip to content

Commit 629ea34

Browse files
author
Eric Jiang
committed
fix(): clean before mount; app quits gracefully
1 parent 1472393 commit 629ea34

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

kernel/daemons/afs.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const debug = require('debug')('ara:fm:kernel:daemons:afsManager')
22

33
const araContracts = require('ara-contracts')
44
const araFilesystem = require('ara-filesystem')
5-
const onExit = require('async-exit-hook')
65
const { events } = require('k')
76
const fs = require('fs')
87
const mirror = require('mirror-folder')
@@ -90,9 +89,6 @@ async function getAfsDownloadStatus(did, shouldBroadcast, password = null) {
9089
debug('Error getting download status %o', err)
9190
}
9291

93-
onExit(async (done) => {
94-
newAfs && await newAfs.close()
95-
})
9692
return { downloadPercent, status }
9793
}
9894

kernel/daemons/fuse.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const { createAFSKeyPath } = require('ara-filesystem/key-path')
33
const { mount: afsMount } = require('cfsnet/fuse')
44
const { readFileMetadata } = require('./utils')
55
const { getAFMDirectory } = require('./afm')
6+
const onExit = require('async-exit-hook')
7+
const { umount } = require('umount')
68
const mkdirp = require('mkdirp')
9+
const rimraf = require('rimraf')
710
const pify = require('pify')
811
const path = require('path')
912

@@ -13,9 +16,11 @@ async function mount(afs) {
1316

1417
const mntPath = path.resolve(path.join(getAFMDirectory(), '/mnt'), title)
1518

16-
await pify(mkdirp)(mntPath)
1719
debug(`mounting ${did} at ${mntPath} ...`)
1820

21+
await clean()
22+
await pify(mkdirp)(mntPath)
23+
1924
await afsMount(mntPath, afs, {
2025
displayFolder: true,
2126
force: true,
@@ -27,6 +32,27 @@ async function mount(afs) {
2732
})
2833

2934
debug('mounted.')
35+
36+
onExit(async (done) => {
37+
await clean()
38+
done()
39+
})
40+
41+
async function clean() {
42+
debug('cleaning')
43+
try{
44+
await pify(umount)(mntPath)
45+
} catch (err) {
46+
debug(err.message)
47+
}
48+
49+
try {
50+
await pify(rimraf)(mntPath)
51+
} catch (err) {
52+
debug(err.message)
53+
}
54+
debug('cleaned.')
55+
}
3056
}
3157

3258
module.exports = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"styleUtils": "file:browser/lib/styleUtils",
6464
"toiletdb": "^1.4.1",
6565
"truffle": "^4.1.14",
66+
"umount": "^1.1.6",
6667
"universal-analytics": "^0.4.20",
6768
"user-home": "^2.0.0",
6869
"uuid": "^3.3.2",

0 commit comments

Comments
 (0)