From d401e55570b8cda84878deb5df7783d27c85cbd9 Mon Sep 17 00:00:00 2001 From: Antonio Noca Date: Sat, 14 Oct 2017 12:33:27 +0100 Subject: [PATCH] Proposed fix for #99 Using fs.unlink to remove symlink if exists. Added test. --- Gruntfile.js | 7 ++++++- tasks/clean.js | 5 +++++ test/clean_test.js | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index e448842..02cc698 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,6 +10,8 @@ module.exports = function(grunt) { + var fs = require('fs'); + // Project configuration. grunt.initConfig({ jshint: { @@ -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. @@ -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 diff --git a/tasks/clean.js b/tasks/clean.js index c5d8e02..4c26582 100644 --- a/tasks/clean.js +++ b/tasks/clean.js @@ -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(); } diff --git a/test/clean_test.js b/test/clean_test.js index d3567c0..b342c15 100644 --- a/test/clean_test.js +++ b/test/clean_test.js @@ -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(); } };