Skip to content

Commit

Permalink
utils/link: Make less race prone
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
iarna committed May 26, 2017
1 parent de33830 commit ad5a441
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/utils/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
],
Expand Down
2 changes: 1 addition & 1 deletion test/tap/unit-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ad5a441

Please sign in to comment.