diff --git a/lib/grunt/file.js b/lib/grunt/file.js index b5f51a22..604736cd 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -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. @@ -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