Skip to content

Commit

Permalink
Merge pull request Medium#237 from Medium/nick-copy
Browse files Browse the repository at this point in the history
add more logging, and report an error if we can't find the extracted file. Fixes Medium#235
  • Loading branch information
nicks committed Oct 16, 2014
2 parents 2666f7a + 7de3cac commit e2786a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
42 changes: 22 additions & 20 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ncp = require('ncp')
var npmconf = require('npmconf')
var path = require('path')
var request = require('request')
var rimraf = require('rimraf').sync
var rimraf = require('rimraf')
var url = require('url')
var util = require('util')
var which = require('which')
Expand Down Expand Up @@ -316,27 +316,29 @@ function extractDownload(filePath) {


function copyIntoPlace(extractedPath, targetPath) {
rimraf(targetPath)

var deferred = kew.defer()
// Look for the extracted directory, so we can rename it.
var files = fs.readdirSync(extractedPath)
for (var i = 0; i < files.length; i++) {
var file = path.join(extractedPath, files[i])
if (fs.statSync(file).isDirectory() && file.indexOf(helper.version) != -1) {
console.log('Copying extracted folder', file, '->', targetPath)
ncp(file, targetPath, deferred.makeNodeResolver())
break
console.log('Removing', targetPath)
return kew.nfcall(rimraf, targetPath).then(function () {
// Look for the extracted directory, so we can rename it.
var files = fs.readdirSync(extractedPath)
for (var i = 0; i < files.length; i++) {
var file = path.join(extractedPath, files[i])
if (fs.statSync(file).isDirectory() && file.indexOf(helper.version) != -1) {
console.log('Copying extracted folder', file, '->', targetPath)
return kew.nfcall(ncp, file, targetPath)
}
}
}

// Cleanup extracted directory after it's been copied
return deferred.promise.then(function() {
try {
return rimraf(extractedPath)
} catch (e) {
console.log('Could not find extracted file', files)
throw new Error('Could not find extracted file')
})
.then(function () {
// Cleanup extracted directory after it's been copied
console.log('Removing', extractedPath)
return kew.nfcall(rimraf, extractedPath).fail(function (e) {
// Swallow the error quietly.
console.warn(e)
console.warn('Unable to remove temporary files at "' + extractedPath +
'", see https://github.com/Obvious/phantomjs/issues/108 for details.')
}
});
})
})
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phantomjs",
"version": "1.9.10",
"version": "1.9.11",
"keywords": [
"phantomjs",
"headless",
Expand Down Expand Up @@ -47,7 +47,7 @@
"progress": "1.1.8",
"request": "2.42.0",
"request-progress": "0.3.1",
"rimraf": "~2.2.2",
"rimraf": "~2.2.8",
"which": "~1.0.5"
},
"devDependencies": {
Expand Down

0 comments on commit e2786a2

Please sign in to comment.