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

Fix symlink test #1742

Merged
merged 1 commit into from Apr 11, 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
2 changes: 0 additions & 2 deletions lib/grunt/file.js
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
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