Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove .nolocal (remnant from prebuild) #81

Merged
merged 1 commit into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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