Skip to content

Commit 2c1d3c0

Browse files
authored
Merge pull request #720 from 2called-chaos/fix-remove-file-unlinks-symlinks
`remove_file` should unlink broken symlinks
2 parents 84c57f6 + ec3a942 commit 2c1d3c0

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
@@ -331,7 +331,7 @@ def remove_file(path, config = {})
331331
path = File.expand_path(path, destination_root)
332332

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

spec/actions/file_manipulation_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ def file
256256
expect(File.exist?(file)).to be false
257257
end
258258

259+
it "removes broken symlinks too" do
260+
link_path = File.join(destination_root, "broken_symlink")
261+
::FileUtils.ln_s("invalid_reference", link_path)
262+
action :remove_file, "broken_symlink"
263+
expect(File.symlink?(link_path) || File.exist?(link_path)).to be false
264+
end
265+
259266
it "removes directories too" do
260267
action :remove_dir, "doc"
261268
expect(File.exist?(File.join(destination_root, "doc"))).to be false

0 commit comments

Comments
 (0)