Skip to content
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
8 changes: 7 additions & 1 deletion lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,13 @@ def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,
st = File.stat(s)
unless File.exist?(d) and compare_file(s, d)
remove_file d, true
copy_file s, d
if d.end_with?('/')
mkdir_p d
copy_file s, d + File.basename(s)
else
mkdir_p File.expand_path('..', d)
copy_file s, d
end
File.utime st.atime, st.mtime, d if preserve
File.chmod fu_mode(mode, st), d if mode
File.chown uid, gid, d if uid or gid
Expand Down
8 changes: 8 additions & 0 deletions test/fileutils/test_fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,14 @@ def test_install_pathname
install Pathname.new('tmp/a'), 'tmp/b'
rm_f 'tmp/a'; touch 'tmp/a'
install Pathname.new('tmp/a'), Pathname.new('tmp/b')
my_rm_rf 'tmp/new_dir_end_with_slash'
install Pathname.new('tmp/a'), 'tmp/new_dir_end_with_slash/'
my_rm_rf 'tmp/new_dir_end_with_slash'
my_rm_rf 'tmp/new_dir'
install Pathname.new('tmp/a'), 'tmp/new_dir/a'
my_rm_rf 'tmp/new_dir'
install Pathname.new('tmp/a'), 'tmp/new_dir/new_dir_end_with_slash/'
my_rm_rf 'tmp/new_dir'
rm_f 'tmp/a'
touch 'tmp/a'
touch 'tmp/b'
Expand Down