Skip to content

Commit d401e55

Browse files
committed
Proposed fix for gruntjs#99
Using fs.unlink to remove symlink if exists. Added test.
1 parent 271defc commit d401e55

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Gruntfile.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
module.exports = function(grunt) {
1212

13+
var fs = require('fs');
14+
1315
// Project configuration.
1416
grunt.initConfig({
1517
jshint: {
@@ -30,7 +32,8 @@ module.exports = function(grunt) {
3032
src: ['tmp/sample_long']
3133
},
3234
exclude: ['tmp/end_01/**/*', '!tmp/end_01/1.txt'],
33-
excludeSub: ['tmp/end_02/**/*.*', '!tmp/end_02/2/**/*']
35+
excludeSub: ['tmp/end_02/**/*.*', '!tmp/end_02/2/**/*'],
36+
symlink: ['tmp/symlink']
3437
},
3538

3639
// Unit tests.
@@ -52,6 +55,8 @@ module.exports = function(grunt) {
5255
grunt.file.copy('test/fixtures/sample_long/long.txt', 'tmp/sample_long/long.txt');
5356
grunt.file.copy('test/fixtures/sample_short/short.txt', 'tmp/sample_short/short.txt');
5457

58+
fs.symlinkSync('tmp/broken-symlink', 'tmp/symlink', 'dir');
59+
5560
var cwd = 'test/fixtures/start';
5661
grunt.file.expand({
5762
cwd: cwd

tasks/clean.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
'use strict';
1010

1111
var async = require('async');
12+
var fs = require("fs");
1213
var rimraf = require('rimraf');
1314

1415
module.exports = function(grunt) {
1516

1617
function clean(filepath, options, done) {
18+
1719
if (!grunt.file.exists(filepath)) {
20+
try {
21+
fs.unlinkSync(filepath);
22+
} catch (err) {}
1823
return done();
1924
}
2025

test/clean_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ exports.clean = {
2929
var res = dircompare.compareSync('test/expected/end_02', 'tmp/end_02');
3030
test.equal(true, res.same, 'should match exclusions for sub');
3131
test.done();
32+
},
33+
symlink: function (test) {
34+
var res = grunt.file.exists('tmp/symlink');
35+
test.equal(false, res, 'should delete broken symlink');
36+
test.done();
3237
}
3338
};

0 commit comments

Comments
 (0)