[ruby/fileutils] Add mkdir_p to FileUtils.install
(https://github.com/ruby/fileutils/pull/104) * Add mkdir_p to FileUtils.install * Adjust raise message. * adjust raise language * handle trailing slash in dest * simplify * Add tests
This commit is contained in:
parent
194520f80e
commit
94aed6ece5
@ -1642,7 +1642,13 @@ module FileUtils
|
|||||||
st = File.stat(s)
|
st = File.stat(s)
|
||||||
unless File.exist?(d) and compare_file(s, d)
|
unless File.exist?(d) and compare_file(s, d)
|
||||||
remove_file d, true
|
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.utime st.atime, st.mtime, d if preserve
|
||||||
File.chmod fu_mode(mode, st), d if mode
|
File.chmod fu_mode(mode, st), d if mode
|
||||||
File.chown uid, gid, d if uid or gid
|
File.chown uid, gid, d if uid or gid
|
||||||
|
@ -1237,6 +1237,14 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
install Pathname.new('tmp/a'), 'tmp/b'
|
install Pathname.new('tmp/a'), 'tmp/b'
|
||||||
rm_f 'tmp/a'; touch 'tmp/a'
|
rm_f 'tmp/a'; touch 'tmp/a'
|
||||||
install Pathname.new('tmp/a'), Pathname.new('tmp/b')
|
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'
|
rm_f 'tmp/a'
|
||||||
touch 'tmp/a'
|
touch 'tmp/a'
|
||||||
touch 'tmp/b'
|
touch 'tmp/b'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user