Skip to content

Commit ec3a942

Browse files
committed
Remove broken symlinks
1 parent 34df888 commit ec3a942

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/thor/actions/file_manipulation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def remove_file(path, config = {})
329329
path = File.expand_path(path, destination_root)
330330

331331
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
332-
if !options[:pretend] && File.exist?(path)
332+
if !options[:pretend] && (File.exist?(path) || File.symlink?(path))
333333
require "fileutils"
334334
::FileUtils.rm_rf(path)
335335
end

spec/actions/file_manipulation_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ def file
259259
expect(File.exist?(file)).to be false
260260
end
261261

262+
it "removes broken symlinks too" do
263+
link_path = File.join(destination_root, "broken_symlink")
264+
::FileUtils.ln_s("invalid_reference", link_path)
265+
action :remove_file, "broken_symlink"
266+
expect(File.symlink?(link_path) || File.exist?(link_path)).to be false
267+
end
268+
262269
it "removes directories too" do
263270
action :remove_dir, "doc"
264271
expect(File.exist?(File.join(destination_root, "doc"))).to be false

0 commit comments

Comments
 (0)