diff options
author | Rebecca Turner <me@re-becca.org> | 2017-05-23 00:17:36 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-05-26 04:55:29 +0300 |
commit | ad5a441288fb6b510d8c1995732e422f2604169e (patch) | |
tree | a7f76d49b5920f2e5cdb59d2c915a58c66caef98 | |
parent | de3383079372c10c8316dcae764a467348e80778 (diff) |
utils/link: Make less race prone
Previously it was gently-rming it's target before making a new target
directory. gently-rm vacuums, removing empty directories. This was fine
until you run more than one `link` command concurrently, at which point it's
entirely possible for one invocation to `mkdir` the directory, then
immediately have another one `gently-rm` it, at which point the symlink
fails. Races!
-rw-r--r-- | lib/utils/link.js | 2 | ||||
-rw-r--r-- | test/tap/unit-link.js | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/utils/link.js b/lib/utils/link.js index 605b77402..15331740a 100644 --- a/lib/utils/link.js +++ b/lib/utils/link.js @@ -64,7 +64,7 @@ function link (from, to, gently, abs, cb) { [ [ensureFromIsNotSource, absTarget, to], [fs, 'stat', absTarget], - [rm, to, gently], + [rm, to, gently, path.dirname(to)], [mkdir, path.dirname(to)], [fs, 'symlink', target, to, 'junction'] ], diff --git a/test/tap/unit-link.js b/test/tap/unit-link.js index e4b909406..4f4083e11 100644 --- a/test/tap/unit-link.js +++ b/test/tap/unit-link.js @@ -227,7 +227,7 @@ function testLink (opts, cb) { } } }, - '../../lib/utils/gently-rm.js': dezalgo(function (toRemove, gently, cb) { + '../../lib/utils/gently-rm.js': dezalgo(function (toRemove, gently, basedir, cb) { if (opts.rm[toRemove] && opts.rm[toRemove].gently === gently) { cb() } else { |