Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
fix(git): cleaner handling of git tarball streams when caching
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 7, 2017
1 parent d4d4917 commit 11acd0a
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions lib/handlers/git/tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ const path = require('path')
const pipe = BB.promisify(require('mississippi').pipe)
const rimraf = BB.promisify(require('rimraf'))
const tar = require('tar-fs')
const to = require('mississippi').to
const uniqueFilename = require('unique-filename')

const gitManifest = require('./manifest')

module.exports = tarball
function tarball (spec, opts) {
opts = optCheck(opts)
let streamErr = null
const stream = new PassThrough().on('error', e => { streamErr = e })
const stream = new PassThrough()
gitManifest(spec, opts).then(manifest => {
if (streamErr) { throw streamErr }
return pipe(fromManifest(manifest, spec, opts), stream)
})
}, err => stream.emit('error', err))
return stream
}

Expand All @@ -46,7 +43,7 @@ function fromManifest (manifest, spec, opts) {
return stream.emit('error', err)
} else {
stream.emit('reset')
withTmp(opts, tmp => {
return withTmp(opts, tmp => {
if (streamError) { throw streamError }
return cloneRepo(
manifest._repo, manifest._ref, manifest._rawRef, tmp, opts
Expand Down Expand Up @@ -100,20 +97,9 @@ function packDir (spec, label, tmp, target, opts) {
const cacher = cache.put.stream(
opts.cache, cache.key('git-clone', label), opts
)
cacher.once('error', err => packer.emit('error', err))
target.once('error', err => packer.emit('error', err))
packer.once('error', err => {
cacher.emit('error', err)
target.emit('error', err)
})
return pipe(packer, to((chunk, enc, cb) => {
cacher.write(chunk, enc, () => {
target.write(chunk, enc, cb)
})
}, done => {
cacher.end(() => {
target.end(done)
})
}))
return Promise.all([
pipe(packer, cacher),
pipe(packer, target)
])
}
}

0 comments on commit 11acd0a

Please sign in to comment.