Skip to content

Commit

Permalink
Proposed fix for gruntjs#99
Browse files Browse the repository at this point in the history
Using fs.unlink to remove symlink if exists.
Added test.
  • Loading branch information
antonionoca committed Oct 14, 2017
1 parent 271defc commit d401e55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

module.exports = function(grunt) {

var fs = require('fs');

// Project configuration.
grunt.initConfig({
jshint: {
Expand All @@ -30,7 +32,8 @@ module.exports = function(grunt) {
src: ['tmp/sample_long']
},
exclude: ['tmp/end_01/**/*', '!tmp/end_01/1.txt'],
excludeSub: ['tmp/end_02/**/*.*', '!tmp/end_02/2/**/*']
excludeSub: ['tmp/end_02/**/*.*', '!tmp/end_02/2/**/*'],
symlink: ['tmp/symlink']
},

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

fs.symlinkSync('tmp/broken-symlink', 'tmp/symlink', 'dir');

var cwd = 'test/fixtures/start';
grunt.file.expand({
cwd: cwd
Expand Down
5 changes: 5 additions & 0 deletions tasks/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
'use strict';

var async = require('async');
var fs = require("fs");
var rimraf = require('rimraf');

module.exports = function(grunt) {

function clean(filepath, options, done) {

if (!grunt.file.exists(filepath)) {
try {
fs.unlinkSync(filepath);
} catch (err) {}
return done();
}

Expand Down
5 changes: 5 additions & 0 deletions test/clean_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ exports.clean = {
var res = dircompare.compareSync('test/expected/end_02', 'tmp/end_02');
test.equal(true, res.same, 'should match exclusions for sub');
test.done();
},
symlink: function (test) {
var res = grunt.file.exists('tmp/symlink');
test.equal(false, res, 'should delete broken symlink');
test.done();
}
};

0 comments on commit d401e55

Please sign in to comment.