Method: Bundler::FileUtils.install
- Defined in:
- lib/bundler/vendor/fileutils/lib/fileutils.rb
.install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil) ⇒ Object
Copies a file entry. See install(1).
Arguments src (a single path or an array of paths) and dest (a single path) should be interpretable as paths;
If the entry at dest does not exist, copies from src to dest:
File.read('src0.txt') # => "aaa\n"
File.exist?('dest0.txt') # => false
Bundler::FileUtils.install('src0.txt', 'dest0.txt')
File.read('dest0.txt') # => "aaa\n"
If dest is a file entry, copies from src to dest, overwriting:
File.read('src1.txt') # => "aaa\n"
File.read('dest1.txt') # => "bbb\n"
Bundler::FileUtils.install('src1.txt', 'dest1.txt')
File.read('dest1.txt') # => "aaa\n"
If dest is a directory entry, copies from src to dest/src, overwriting if necessary:
File.read('src2.txt') # => "aaa\n"
File.read('dest2/src2.txt') # => "bbb\n"
Bundler::FileUtils.install('src2.txt', 'dest2')
File.read('dest2/src2.txt') # => "aaa\n"
If src is an array of paths and dest points to a directory, copies each path path in src to dest/path:
File.file?('src3.txt') # => true
File.file?('src3.dat') # => true
Bundler::FileUtils.mkdir('dest3')
Bundler::FileUtils.install(['src3.txt', 'src3.dat'], 'dest3')
File.file?('dest3/src3.txt') # => true
File.file?('dest3/src3.dat') # => true
Keyword arguments:
-
group: <i>group</i>- changes the group if notnil, using File.chown. -
mode: <i>permissions</i>- changes the permissions. using File.chmod. -
noop: true- does not copy entries; returnsnil. -
owner: <i>owner</i>- changes the owner if notnil, using File.chown. -
preserve: true- preserve timestamps using File.utime. -
verbose: true- prints an equivalent command:Bundler::FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true) Bundler::FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true) Bundler::FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)Output:
install -c src0.txt dest0.txt install -c src1.txt dest1.txt install -c src2.txt dest2
Related: methods for copying.
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1607 def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil) if verbose msg = +"install -c" msg << ' -p' if preserve msg << ' -m ' << mode_to_s(mode) if mode msg << " -o #{owner}" if owner msg << " -g #{group}" if group msg << ' ' << [src,dest].flatten.join(' ') msg end return if noop uid = fu_get_uid(owner) gid = fu_get_gid(group) fu_each_src_dest(src, dest) do |s, d| st = File.stat(s) unless File.exist?(d) and compare_file(s, d) remove_file d, true if d.end_with?('/') mkdir_p d copy_file s, d + File.basename(s) else mkdir_p File.('..', 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 end end end |