From 0ffa1e72d0a7f3c64670fa1ab44f20885bbbaaf7 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 6 Jan 2016 16:31:01 +0000 Subject: [PATCH] Attempt to remove temp file after install #331 --- binding.js | 16 ++++++++++++---- docs/changelog.md | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/binding.js b/binding.js index fb97c642..93eb9e37 100644 --- a/binding.js +++ b/binding.js @@ -25,7 +25,7 @@ var isFile = function(file) { return exists; }; -var unpack = function(tarPath) { +var unpack = function(tarPath, done) { var extractor = tar.Extract({ path: __dirname }); @@ -34,6 +34,9 @@ var unpack = function(tarPath) { if (!isFile(vipsHeaderPath)) { error('Could not unpack ' + tarPath); } + if (typeof done === 'function') { + done(); + } }); fs.createReadStream(tarPath).on('error', error) .pipe(zlib.Unzip()) @@ -73,10 +76,15 @@ module.exports.download_vips = function() { if (isFile(tarPath)) { unpack(tarPath); } else { - // Download - tarPath = path.join(tmp, tarFilename); + // Download to per-process temporary file + tarPath = path.join(tmp, process.pid + '-' + tarFilename); var tmpFile = fs.createWriteStream(tarPath).on('finish', function() { - unpack(tarPath); + unpack(tarPath, function() { + // Attempt to remove temporary file + try { + fs.unlinkSync(tarPath); + } catch (err) {} + }); }); var options = { url: distBaseUrl + tarFilename diff --git a/docs/changelog.md b/docs/changelog.md index 86069b98..bfe8360d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,10 @@ [#326](https://github.com/lovell/sharp/issues/326) [@c0decafe](https://github.com/c0decafe) +* Attempt to remove temporary file after installation. + [#331](https://github.com/lovell/sharp/issues/331) + [@dtoubelis](https://github.com/dtoubelis) + #### v0.12.1 - 12th December 2015 * Allow use of SIMD vector instructions (via liborc) to be toggled on/off.