Skip to content

Commit

Permalink
fix(install): fix dat install process
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Aug 19, 2017
1 parent 76e3281 commit 5a630bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
7 changes: 5 additions & 2 deletions lib/install/installer/dat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Dat = require('../../utils/dat')

module.exports = (pkg, cwd) => {
return new Promise((resolve, reject) => {
Dat(cwd, {key: pkg.url, sparse: true}, (e, dat) => {
Dat(cwd, {key: pkg.url}, (e, dat) => {
if (e) return reject(e)
dat.joinNetwork()
const archive = dat.archive
Expand All @@ -16,7 +16,10 @@ module.exports = (pkg, cwd) => {
if (st.downloaded !== st.length) {
reject('all blocks are not downloaded')
}
resolve()
dat.close((e) => {
if (e) reject(e)
resolve()
})
})
})
})
Expand Down
28 changes: 15 additions & 13 deletions lib/install/resolver/fetchers/dat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ module.exports = (name, spec, result) => {
reject(e)
}
if (!content) return
dat.leaveNetwork()
rimraf.sync(tmp)
try {
const pkg = JSON.parse(content.toString())
resolve({
type: 'dat',
version: pkg.version,
dependencies: pkg.dependencies,
url: spec
})
} catch (e) {
reject(e)
}
dat.close((e) => {
if (e) reject(e)
rimraf.sync(tmp)
try {
const pkg = JSON.parse(content.toString())
resolve({
type: 'dat',
version: pkg.version,
dependencies: pkg.dependencies,
url: spec
})
} catch (e) {
reject(e)
}
})
})
})
})
Expand Down

0 comments on commit 5a630bb

Please sign in to comment.