Skip to content

Commit

Permalink
Use copy+unlink if rename fails during install #1345
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 20, 2018
1 parent a15a9b9 commit ece1112
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.md
Expand Up @@ -4,6 +4,11 @@

Requires libvips v8.6.1.

#### v0.20.7 - TBD

* Use copy+unlink if rename operation fails during installation.
[#1345](https://github.com/lovell/sharp/issues/1345)

#### v0.20.6 - 20<sup>th</sup> August 2018

* Add removeAlpha operation to remove alpha channel, if any.
Expand Down
10 changes: 9 additions & 1 deletion install/libvips.js
Expand Up @@ -9,6 +9,7 @@ const npmLog = require('npmlog');
const semver = require('semver');
const simpleGet = require('simple-get');
const tar = require('tar');
const copyFileSync = require('fs-copy-file-sync');

const agent = require('../lib/agent');
const libvips = require('../lib/libvips');
Expand Down Expand Up @@ -82,7 +83,14 @@ try {
response.pipe(tmpFile);
});
tmpFile.on('close', function () {
fs.renameSync(tarPathTemp, tarPathCache);
try {
// Attempt to rename
fs.renameSync(tarPathTemp, tarPathCache);
} catch (err) {
// Fall back to copy and unlink
copyFileSync(tarPathTemp, tarPathCache);
fs.unlinkSync(tarPathTemp);
}
extractTarball(tarPathCache);
});
}
Expand Down

0 comments on commit ece1112

Please sign in to comment.