Skip to content

Commit

Permalink
remove .nolocal 🔥 (remnant from prebuild)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed May 4, 2018
1 parent d90cfac commit a069253
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 62 deletions.
93 changes: 38 additions & 55 deletions download.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,58 @@ var mkdirp = require('mkdirp')

function downloadPrebuild (downloadUrl, opts, cb) {
var cachedPrebuild = util.cachedPrebuild(downloadUrl)
var localPrebuild = util.localPrebuild(downloadUrl)
var tempFile = util.tempFile(cachedPrebuild)

var log = opts.log || noop

if (opts.nolocal) return download()

log.info('looking for local prebuild @', localPrebuild)
fs.access(localPrebuild, fs.R_OK | fs.W_OK, function (err) {
if (err && err.code === 'ENOENT') {
return download()
}

log.info('found local prebuild')
cachedPrebuild = localPrebuild
unpack()
})

function download () {
ensureNpmCacheDir(function (err) {
if (err) return onerror(err)
ensureNpmCacheDir(function (err) {
if (err) return onerror(err)

log.info('looking for cached prebuild @', cachedPrebuild)
fs.access(cachedPrebuild, fs.R_OK | fs.W_OK, function (err) {
if (!(err && err.code === 'ENOENT')) {
log.info('found cached prebuild')
return unpack()
}
log.info('looking for cached prebuild @', cachedPrebuild)
fs.access(cachedPrebuild, fs.R_OK | fs.W_OK, function (err) {
if (!(err && err.code === 'ENOENT')) {
log.info('found cached prebuild')
return unpack()
}

log.http('request', 'GET ' + downloadUrl)
var reqOpts = proxy({ url: downloadUrl }, opts)
log.http('request', 'GET ' + downloadUrl)
var reqOpts = proxy({ url: downloadUrl }, opts)

if (opts.token) {
reqOpts.url += '?access_token=' + opts.token
reqOpts.headers = {
'User-Agent': 'simple-get',
'Accept': 'application/octet-stream'
}
if (opts.token) {
reqOpts.url += '?access_token=' + opts.token
reqOpts.headers = {
'User-Agent': 'simple-get',
'Accept': 'application/octet-stream'
}
}

var req = get(reqOpts, function (err, res) {
if (err) return onerror(err)
log.http(res.statusCode, downloadUrl)
if (res.statusCode !== 200) return onerror()
mkdirp(util.prebuildCache(), function () {
log.info('downloading to @', tempFile)
pump(res, fs.createWriteStream(tempFile), function (err) {
if (err) return onerror(err)
fs.rename(tempFile, cachedPrebuild, function (err) {
if (err) return cb(err)
log.info('renaming to @', cachedPrebuild)
unpack()
})
var req = get(reqOpts, function (err, res) {
if (err) return onerror(err)
log.http(res.statusCode, downloadUrl)
if (res.statusCode !== 200) return onerror()
mkdirp(util.prebuildCache(), function () {
log.info('downloading to @', tempFile)
pump(res, fs.createWriteStream(tempFile), function (err) {
if (err) return onerror(err)
fs.rename(tempFile, cachedPrebuild, function (err) {
if (err) return cb(err)
log.info('renaming to @', cachedPrebuild)
unpack()
})
})
})

req.setTimeout(30 * 1000, function () {
req.abort()
})
})

function onerror (err) {
fs.unlink(tempFile, function () {
cb(err || error.noPrebuilts(opts))
})
}
req.setTimeout(30 * 1000, function () {
req.abort()
})
})
}

function onerror (err) {
fs.unlink(tempFile, function () {
cb(err || error.noPrebuilts(opts))
})
}
})

function unpack () {
var binaryName
Expand Down
1 change: 0 additions & 1 deletion test/asset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ test('non existing version should fail asset request', function (t) {
function getOpts () {
return {
pkg: require('a-native-module/package'),
nolocal: true,
runtime: 'node',
platform: process.platform,
arch: process.arch,
Expand Down
1 change: 0 additions & 1 deletion test/download-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ test('should fail if abi is system abi with invalid binary', function (t) {
function getOpts () {
return {
pkg: require('a-native-module/package'),
nolocal: true,
runtime: 'node',
platform: process.platform,
arch: process.arch,
Expand Down
5 changes: 0 additions & 5 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ function tempFile (cached) {
return cached + '.' + process.pid + '-' + Math.random().toString(16).slice(2) + '.tmp'
}

function localPrebuild (url) {
return path.join('prebuilds', path.basename(url))
}

exports.getDownloadUrl = getDownloadUrl
exports.getApiUrl = getApiUrl
exports.getAssetUrl = getAssetUrl
exports.urlTemplate = urlTemplate
exports.cachedPrebuild = cachedPrebuild
exports.localPrebuild = localPrebuild
exports.prebuildCache = prebuildCache
exports.npmCache = npmCache
exports.tempFile = tempFile

0 comments on commit a069253

Please sign in to comment.