Skip to content

Commit

Permalink
Fix symlink test
Browse files Browse the repository at this point in the history
  • Loading branch information
vladikoff committed Apr 11, 2022
1 parent a7ab0a8 commit 0652305
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions lib/grunt/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,12 @@ file._isSymbolicLink = function() {

file._copySymbolicLink = function(srcpath, destpath) {
var destdir = path.join(destpath, '..');
var fileBase = path.basename(srcpath);
// Use the correct relative path for the symlink
if (!grunt.file.isPathAbsolute(srcpath)) {
srcpath = path.relative(destdir, srcpath) || '.';
}
file.mkdir(destdir);
var mode = grunt.file.isDir(srcpath) ? 'dir' : 'file';
var destpath = path.join(destpath, fileBase);
if (fs.existsSync(destpath)) {
// skip symlink if file already exists
return;
Expand Down
5 changes: 3 additions & 2 deletions test/grunt/file_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ exports.file = {
fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(srcfile.path, 'octocat.png'), 'file');
// test symlink copy for files
var destdir = new Tempdir();
grunt.file.copy(path.join(srcfile.path, 'octocat.png'), destdir.path);
grunt.file.copy(path.join(srcfile.path, 'octocat.png'), path.join(destdir.path, 'octocat.png'));
test.ok(fs.lstatSync(path.join(srcfile.path, 'octocat.png')).isSymbolicLink());
test.ok(fs.lstatSync(path.join(destdir.path, 'octocat.png')).isSymbolicLink());

Expand All @@ -908,9 +908,10 @@ exports.file = {
var destdir = new Tempdir();
var fixtures = path.resolve('test/fixtures');
var symlinkSource = path.join(srcdir.path, path.basename(fixtures));
var destSource = path.join(destdir.path, path.basename(fixtures));
fs.symlinkSync(fixtures, symlinkSource, 'dir');

grunt.file.copy(symlinkSource, destdir.path);
grunt.file.copy(symlinkSource, destSource);
test.ok(fs.lstatSync(symlinkSource).isSymbolicLink());
test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink());
test.done();
Expand Down

0 comments on commit 0652305

Please sign in to comment.