Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch up race condition in symlink copying. #1745

Merged
merged 1 commit into from May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
v1.5.3
date: 2022-04-23
changes:
- Patch up race condition in symlink copying.
v1.5.2
date: 2022-04-12
changes:
Expand Down
9 changes: 2 additions & 7 deletions lib/grunt/file.js
Expand Up @@ -294,11 +294,6 @@ file.write = function(filepath, contents, options) {
// processing content, writing output.
// Handles symlinks by coping them as files or directories.
file.copy = function copy(srcpath, destpath, options) {
if (file.isLink(destpath)) {
// in case destpath is a symlink, avoid following the symlink, instead overwrite it later
fs.unlinkSync(destpath);
}

if (file.isLink(srcpath)) {
file._copySymbolicLink(srcpath, destpath);
} else if (file.isDir(srcpath)) {
Expand Down Expand Up @@ -338,8 +333,8 @@ file._copy = function(srcpath, destpath, options) {
}
}
// Abort copy if the process function returns false.
if (contents === false) {
grunt.verbose.writeln('Write aborted.');
if (contents === false || file.isLink(destpath)) {
grunt.verbose.writeln('Write aborted. Either the process function returned false or the destination is a symlink');
} else {
file.write(destpath, contents, readWriteOptions);
}
Expand Down
10 changes: 9 additions & 1 deletion test/grunt/file_test.js
Expand Up @@ -916,5 +916,13 @@ exports.file = {
test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink());
test.done();
},
}
},
'symbolicLinkDestError': function(test) {
test.expect(1);
var tmpfile = new Tempdir();
fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'), 'file');
grunt.file.copy(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'));
test.ok(fs.lstatSync(path.join(tmpfile.path, 'octocat.png')).isSymbolicLink());
test.done();
},
};