Skip to content

Commit 58016ff

Browse files
committedMay 10, 2022
Patch up race condition in symlink copying.
1 parent ac667b2 commit 58016ff

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed
 

Diff for: ‎CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.5.3
2+
date: 2022-04-23
3+
changes:
4+
- Patch up race condition in symlink copying.
15
v1.5.2
26
date: 2022-04-12
37
changes:

Diff for: ‎lib/grunt/file.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,6 @@ file.write = function(filepath, contents, options) {
294294
// processing content, writing output.
295295
// Handles symlinks by coping them as files or directories.
296296
file.copy = function copy(srcpath, destpath, options) {
297-
if (file.isLink(destpath)) {
298-
// in case destpath is a symlink, avoid following the symlink, instead overwrite it later
299-
fs.unlinkSync(destpath);
300-
}
301-
302297
if (file.isLink(srcpath)) {
303298
file._copySymbolicLink(srcpath, destpath);
304299
} else if (file.isDir(srcpath)) {
@@ -338,8 +333,8 @@ file._copy = function(srcpath, destpath, options) {
338333
}
339334
}
340335
// Abort copy if the process function returns false.
341-
if (contents === false) {
342-
grunt.verbose.writeln('Write aborted.');
336+
if (contents === false || file.isLink(destpath)) {
337+
grunt.verbose.writeln('Write aborted. Either the process function returned false or the destination is a symlink');
343338
} else {
344339
file.write(destpath, contents, readWriteOptions);
345340
}

Diff for: ‎test/grunt/file_test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -916,5 +916,13 @@ exports.file = {
916916
test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink());
917917
test.done();
918918
},
919-
}
919+
},
920+
'symbolicLinkDestError': function(test) {
921+
test.expect(1);
922+
var tmpfile = new Tempdir();
923+
fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'), 'file');
924+
grunt.file.copy(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'));
925+
test.ok(fs.lstatSync(path.join(tmpfile.path, 'octocat.png')).isSymbolicLink());
926+
test.done();
927+
},
920928
};

0 commit comments

Comments
 (0)