module Bundler::FileUtils

def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,


Related: {methods for copying}[rdoc-ref:FileUtils@Copying].

install -c src2.txt dest2
install -c src1.txt dest1.txt
install -c src0.txt dest0.txt

Output:

Bundler::FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)
Bundler::FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true)
Bundler::FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true)

- verbose: true - prints an equivalent command:
using {File.utime}[https://docs.ruby-lang.org/en/master/File.html#method-c-utime].
- preserve: true - preserve timestamps
using {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
- owner: owner - changes the owner if not +nil+,
- noop: true - does not copy entries; returns +nil+.
using {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
- mode: permissions - changes the permissions.
using {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
- group: group - changes the group if not +nil+,

Keyword arguments:

File.file?('dest3/src3.dat') # => true
File.file?('dest3/src3.txt') # => true
Bundler::FileUtils.install(['src3.txt', 'src3.dat'], 'dest3')
Bundler::FileUtils.mkdir('dest3')
File.file?('src3.dat') # => true
File.file?('src3.txt') # => true

copies each path +path+ in +src+ to dest/path:
If +src+ is an array of paths and +dest+ points to a directory,

File.read('dest2/src2.txt') # => "aaa\n"
Bundler::FileUtils.install('src2.txt', 'dest2')
File.read('dest2/src2.txt') # => "bbb\n"
File.read('src2.txt') # => "aaa\n"

overwriting if necessary:
If +dest+ is a directory entry, copies from +src+ to dest/src,

File.read('dest1.txt') # => "aaa\n"
Bundler::FileUtils.install('src1.txt', 'dest1.txt')
File.read('dest1.txt') # => "bbb\n"
File.read('src1.txt') # => "aaa\n"

If +dest+ is a file entry, copies from +src+ to +dest+, overwriting:

File.read('dest0.txt') # => "aaa\n"
Bundler::FileUtils.install('src0.txt', 'dest0.txt')
File.exist?('dest0.txt') # => false
File.read('src0.txt') # => "aaa\n"

If the entry at +dest+ does not exist, copies from +src+ to +dest+:

should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments];
and +dest+ (a single path)
Arguments +src+ (a single path or an array of paths)

See {install(1)}[https://man7.org/linux/man-pages/man1/install.1.html].
Copies a file entry.
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(' ')
    fu_output_message 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.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
    end
  end
end