Skip to content

Commit

Permalink
Merge pull request #1743 from gruntjs/cleanup-link
Browse files Browse the repository at this point in the history
Clean up link handling
  • Loading branch information
vladikoff committed Apr 12, 2022
2 parents d5969ec + 433f91b commit b0ec6e1
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit b0ec6e1

Please sign in to comment.