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

Clean up link handling #1743

Merged
merged 1 commit into from Apr 12, 2022
Merged
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
12 changes: 6 additions & 6 deletions lib/grunt/file.js
Expand Up @@ -294,7 +294,12 @@ 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._isSymbolicLink(srcpath)) {
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)) {
// Copy a directory, recursively.
Expand Down Expand Up @@ -452,11 +457,6 @@ file.isPathCwd = function() {
}
};

file._isSymbolicLink = function() {
var filepath = path.join.apply(path, arguments);
return fs.lstatSync(filepath).isSymbolicLink();
};

file._copySymbolicLink = function(srcpath, destpath) {
var destdir = path.join(destpath, '..');
// Use the correct relative path for the symlink
Expand Down