Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUtis.cp_r cannot overwrite a symlink of directory #9

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
destent = Entry_.new(dest, ent.rel, false)
File.unlink destent.path if remove_destination && File.file?(destent.path)
File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
ent.copy destent.path
end, proc do |ent|
destent = Entry_.new(dest, ent.rel, false)
Expand Down
17 changes: 17 additions & 0 deletions test/fileutils/test_fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ def test_cp_r_pathname
}
end

def test_cp_r_symlink_remove_destination
Dir.mkdir 'tmp/src'
Dir.mkdir 'tmp/dest'
Dir.mkdir 'tmp/src/dir'
File.symlink 'tmp/src/dir', 'tmp/src/a'
cp_r 'tmp/src', 'tmp/dest/', remove_destination: true
cp_r 'tmp/src', 'tmp/dest/', remove_destination: true
end

def test_mv
check_singleton :mv

Expand Down Expand Up @@ -1438,6 +1447,14 @@ def test_copy_entry_symlink
assert_equal 'somewhere', File.readlink('tmp/dirdest/sym')
end if have_symlink?

def test_copy_entry_symlink_remove_destination
Dir.mkdir 'tmp/dir'
File.symlink 'tmp/dir', 'tmp/dest'
touch 'tmp/src'
copy_entry 'tmp/src', 'tmp/dest', false, false, true
assert_file_exist 'tmp/dest'
end

def test_copy_file
check_singleton :copy_file

Expand Down