Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby31/share/ruby
File: fileutils.rb
# frozen_string_literal: true
[0] Fix | Delete
[1] Fix | Delete
begin
[2] Fix | Delete
require 'rbconfig'
[3] Fix | Delete
rescue LoadError
[4] Fix | Delete
# for make mjit-headers
[5] Fix | Delete
end
[6] Fix | Delete
[7] Fix | Delete
#
[8] Fix | Delete
# = fileutils.rb
[9] Fix | Delete
#
[10] Fix | Delete
# Copyright (c) 2000-2007 Minero Aoki
[11] Fix | Delete
#
[12] Fix | Delete
# This program is free software.
[13] Fix | Delete
# You can distribute/modify this program under the same terms of ruby.
[14] Fix | Delete
#
[15] Fix | Delete
# == module FileUtils
[16] Fix | Delete
#
[17] Fix | Delete
# Namespace for several file utility methods for copying, moving, removing, etc.
[18] Fix | Delete
#
[19] Fix | Delete
# === Module Functions
[20] Fix | Delete
#
[21] Fix | Delete
# require 'fileutils'
[22] Fix | Delete
#
[23] Fix | Delete
# FileUtils.cd(dir, **options)
[24] Fix | Delete
# FileUtils.cd(dir, **options) {|dir| block }
[25] Fix | Delete
# FileUtils.pwd()
[26] Fix | Delete
# FileUtils.mkdir(dir, **options)
[27] Fix | Delete
# FileUtils.mkdir(list, **options)
[28] Fix | Delete
# FileUtils.mkdir_p(dir, **options)
[29] Fix | Delete
# FileUtils.mkdir_p(list, **options)
[30] Fix | Delete
# FileUtils.rmdir(dir, **options)
[31] Fix | Delete
# FileUtils.rmdir(list, **options)
[32] Fix | Delete
# FileUtils.ln(target, link, **options)
[33] Fix | Delete
# FileUtils.ln(targets, dir, **options)
[34] Fix | Delete
# FileUtils.ln_s(target, link, **options)
[35] Fix | Delete
# FileUtils.ln_s(targets, dir, **options)
[36] Fix | Delete
# FileUtils.ln_sf(target, link, **options)
[37] Fix | Delete
# FileUtils.cp(src, dest, **options)
[38] Fix | Delete
# FileUtils.cp(list, dir, **options)
[39] Fix | Delete
# FileUtils.cp_r(src, dest, **options)
[40] Fix | Delete
# FileUtils.cp_r(list, dir, **options)
[41] Fix | Delete
# FileUtils.mv(src, dest, **options)
[42] Fix | Delete
# FileUtils.mv(list, dir, **options)
[43] Fix | Delete
# FileUtils.rm(list, **options)
[44] Fix | Delete
# FileUtils.rm_r(list, **options)
[45] Fix | Delete
# FileUtils.rm_rf(list, **options)
[46] Fix | Delete
# FileUtils.install(src, dest, **options)
[47] Fix | Delete
# FileUtils.chmod(mode, list, **options)
[48] Fix | Delete
# FileUtils.chmod_R(mode, list, **options)
[49] Fix | Delete
# FileUtils.chown(user, group, list, **options)
[50] Fix | Delete
# FileUtils.chown_R(user, group, list, **options)
[51] Fix | Delete
# FileUtils.touch(list, **options)
[52] Fix | Delete
#
[53] Fix | Delete
# Possible <tt>options</tt> are:
[54] Fix | Delete
#
[55] Fix | Delete
# <tt>:force</tt> :: forced operation (rewrite files if exist, remove
[56] Fix | Delete
# directories if not empty, etc.);
[57] Fix | Delete
# <tt>:verbose</tt> :: print command to be run, in bash syntax, before
[58] Fix | Delete
# performing it;
[59] Fix | Delete
# <tt>:preserve</tt> :: preserve object's group, user and modification
[60] Fix | Delete
# time on copying;
[61] Fix | Delete
# <tt>:noop</tt> :: no changes are made (usable in combination with
[62] Fix | Delete
# <tt>:verbose</tt> which will print the command to run)
[63] Fix | Delete
#
[64] Fix | Delete
# Each method documents the options that it honours. See also ::commands,
[65] Fix | Delete
# ::options and ::options_of methods to introspect which command have which
[66] Fix | Delete
# options.
[67] Fix | Delete
#
[68] Fix | Delete
# All methods that have the concept of a "source" file or directory can take
[69] Fix | Delete
# either one file or a list of files in that argument. See the method
[70] Fix | Delete
# documentation for examples.
[71] Fix | Delete
#
[72] Fix | Delete
# There are some `low level' methods, which do not accept keyword arguments:
[73] Fix | Delete
#
[74] Fix | Delete
# FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
[75] Fix | Delete
# FileUtils.copy_file(src, dest, preserve = false, dereference = true)
[76] Fix | Delete
# FileUtils.copy_stream(srcstream, deststream)
[77] Fix | Delete
# FileUtils.remove_entry(path, force = false)
[78] Fix | Delete
# FileUtils.remove_entry_secure(path, force = false)
[79] Fix | Delete
# FileUtils.remove_file(path, force = false)
[80] Fix | Delete
# FileUtils.compare_file(path_a, path_b)
[81] Fix | Delete
# FileUtils.compare_stream(stream_a, stream_b)
[82] Fix | Delete
# FileUtils.uptodate?(file, cmp_list)
[83] Fix | Delete
#
[84] Fix | Delete
# == module FileUtils::Verbose
[85] Fix | Delete
#
[86] Fix | Delete
# This module has all methods of FileUtils module, but it outputs messages
[87] Fix | Delete
# before acting. This equates to passing the <tt>:verbose</tt> flag to methods
[88] Fix | Delete
# in FileUtils.
[89] Fix | Delete
#
[90] Fix | Delete
# == module FileUtils::NoWrite
[91] Fix | Delete
#
[92] Fix | Delete
# This module has all methods of FileUtils module, but never changes
[93] Fix | Delete
# files/directories. This equates to passing the <tt>:noop</tt> flag to methods
[94] Fix | Delete
# in FileUtils.
[95] Fix | Delete
#
[96] Fix | Delete
# == module FileUtils::DryRun
[97] Fix | Delete
#
[98] Fix | Delete
# This module has all methods of FileUtils module, but never changes
[99] Fix | Delete
# files/directories. This equates to passing the <tt>:noop</tt> and
[100] Fix | Delete
# <tt>:verbose</tt> flags to methods in FileUtils.
[101] Fix | Delete
#
[102] Fix | Delete
module FileUtils
[103] Fix | Delete
VERSION = "1.6.0"
[104] Fix | Delete
[105] Fix | Delete
def self.private_module_function(name) #:nodoc:
[106] Fix | Delete
module_function name
[107] Fix | Delete
private_class_method name
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
#
[111] Fix | Delete
# Returns the name of the current directory.
[112] Fix | Delete
#
[113] Fix | Delete
def pwd
[114] Fix | Delete
Dir.pwd
[115] Fix | Delete
end
[116] Fix | Delete
module_function :pwd
[117] Fix | Delete
[118] Fix | Delete
alias getwd pwd
[119] Fix | Delete
module_function :getwd
[120] Fix | Delete
[121] Fix | Delete
#
[122] Fix | Delete
# Changes the current directory to the directory +dir+.
[123] Fix | Delete
#
[124] Fix | Delete
# If this method is called with block, resumes to the previous
[125] Fix | Delete
# working directory after the block execution has finished.
[126] Fix | Delete
#
[127] Fix | Delete
# FileUtils.cd('/') # change directory
[128] Fix | Delete
#
[129] Fix | Delete
# FileUtils.cd('/', verbose: true) # change directory and report it
[130] Fix | Delete
#
[131] Fix | Delete
# FileUtils.cd('/') do # change directory
[132] Fix | Delete
# # ... # do something
[133] Fix | Delete
# end # return to original directory
[134] Fix | Delete
#
[135] Fix | Delete
def cd(dir, verbose: nil, &block) # :yield: dir
[136] Fix | Delete
fu_output_message "cd #{dir}" if verbose
[137] Fix | Delete
result = Dir.chdir(dir, &block)
[138] Fix | Delete
fu_output_message 'cd -' if verbose and block
[139] Fix | Delete
result
[140] Fix | Delete
end
[141] Fix | Delete
module_function :cd
[142] Fix | Delete
[143] Fix | Delete
alias chdir cd
[144] Fix | Delete
module_function :chdir
[145] Fix | Delete
[146] Fix | Delete
#
[147] Fix | Delete
# Returns true if +new+ is newer than all +old_list+.
[148] Fix | Delete
# Non-existent files are older than any file.
[149] Fix | Delete
#
[150] Fix | Delete
# FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
[151] Fix | Delete
# system 'make hello.o'
[152] Fix | Delete
#
[153] Fix | Delete
def uptodate?(new, old_list)
[154] Fix | Delete
return false unless File.exist?(new)
[155] Fix | Delete
new_time = File.mtime(new)
[156] Fix | Delete
old_list.each do |old|
[157] Fix | Delete
if File.exist?(old)
[158] Fix | Delete
return false unless new_time > File.mtime(old)
[159] Fix | Delete
end
[160] Fix | Delete
end
[161] Fix | Delete
true
[162] Fix | Delete
end
[163] Fix | Delete
module_function :uptodate?
[164] Fix | Delete
[165] Fix | Delete
def remove_trailing_slash(dir) #:nodoc:
[166] Fix | Delete
dir == '/' ? dir : dir.chomp(?/)
[167] Fix | Delete
end
[168] Fix | Delete
private_module_function :remove_trailing_slash
[169] Fix | Delete
[170] Fix | Delete
#
[171] Fix | Delete
# Creates one or more directories.
[172] Fix | Delete
#
[173] Fix | Delete
# FileUtils.mkdir 'test'
[174] Fix | Delete
# FileUtils.mkdir %w(tmp data)
[175] Fix | Delete
# FileUtils.mkdir 'notexist', noop: true # Does not really create.
[176] Fix | Delete
# FileUtils.mkdir 'tmp', mode: 0700
[177] Fix | Delete
#
[178] Fix | Delete
def mkdir(list, mode: nil, noop: nil, verbose: nil)
[179] Fix | Delete
list = fu_list(list)
[180] Fix | Delete
fu_output_message "mkdir #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
[181] Fix | Delete
return if noop
[182] Fix | Delete
[183] Fix | Delete
list.each do |dir|
[184] Fix | Delete
fu_mkdir dir, mode
[185] Fix | Delete
end
[186] Fix | Delete
end
[187] Fix | Delete
module_function :mkdir
[188] Fix | Delete
[189] Fix | Delete
#
[190] Fix | Delete
# Creates a directory and all its parent directories.
[191] Fix | Delete
# For example,
[192] Fix | Delete
#
[193] Fix | Delete
# FileUtils.mkdir_p '/usr/local/lib/ruby'
[194] Fix | Delete
#
[195] Fix | Delete
# causes to make following directories, if they do not exist.
[196] Fix | Delete
#
[197] Fix | Delete
# * /usr
[198] Fix | Delete
# * /usr/local
[199] Fix | Delete
# * /usr/local/lib
[200] Fix | Delete
# * /usr/local/lib/ruby
[201] Fix | Delete
#
[202] Fix | Delete
# You can pass several directories at a time in a list.
[203] Fix | Delete
#
[204] Fix | Delete
def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
[205] Fix | Delete
list = fu_list(list)
[206] Fix | Delete
fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
[207] Fix | Delete
return *list if noop
[208] Fix | Delete
[209] Fix | Delete
list.each do |item|
[210] Fix | Delete
path = remove_trailing_slash(item)
[211] Fix | Delete
[212] Fix | Delete
stack = []
[213] Fix | Delete
until File.directory?(path) || File.dirname(path) == path
[214] Fix | Delete
stack.push path
[215] Fix | Delete
path = File.dirname(path)
[216] Fix | Delete
end
[217] Fix | Delete
stack.reverse_each do |dir|
[218] Fix | Delete
begin
[219] Fix | Delete
fu_mkdir dir, mode
[220] Fix | Delete
rescue SystemCallError
[221] Fix | Delete
raise unless File.directory?(dir)
[222] Fix | Delete
end
[223] Fix | Delete
end
[224] Fix | Delete
end
[225] Fix | Delete
[226] Fix | Delete
return *list
[227] Fix | Delete
end
[228] Fix | Delete
module_function :mkdir_p
[229] Fix | Delete
[230] Fix | Delete
alias mkpath mkdir_p
[231] Fix | Delete
alias makedirs mkdir_p
[232] Fix | Delete
module_function :mkpath
[233] Fix | Delete
module_function :makedirs
[234] Fix | Delete
[235] Fix | Delete
def fu_mkdir(path, mode) #:nodoc:
[236] Fix | Delete
path = remove_trailing_slash(path)
[237] Fix | Delete
if mode
[238] Fix | Delete
Dir.mkdir path, mode
[239] Fix | Delete
File.chmod mode, path
[240] Fix | Delete
else
[241] Fix | Delete
Dir.mkdir path
[242] Fix | Delete
end
[243] Fix | Delete
end
[244] Fix | Delete
private_module_function :fu_mkdir
[245] Fix | Delete
[246] Fix | Delete
#
[247] Fix | Delete
# Removes one or more directories.
[248] Fix | Delete
#
[249] Fix | Delete
# FileUtils.rmdir 'somedir'
[250] Fix | Delete
# FileUtils.rmdir %w(somedir anydir otherdir)
[251] Fix | Delete
# # Does not really remove directory; outputs message.
[252] Fix | Delete
# FileUtils.rmdir 'somedir', verbose: true, noop: true
[253] Fix | Delete
#
[254] Fix | Delete
def rmdir(list, parents: nil, noop: nil, verbose: nil)
[255] Fix | Delete
list = fu_list(list)
[256] Fix | Delete
fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if verbose
[257] Fix | Delete
return if noop
[258] Fix | Delete
list.each do |dir|
[259] Fix | Delete
Dir.rmdir(dir = remove_trailing_slash(dir))
[260] Fix | Delete
if parents
[261] Fix | Delete
begin
[262] Fix | Delete
until (parent = File.dirname(dir)) == '.' or parent == dir
[263] Fix | Delete
dir = parent
[264] Fix | Delete
Dir.rmdir(dir)
[265] Fix | Delete
end
[266] Fix | Delete
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
[267] Fix | Delete
end
[268] Fix | Delete
end
[269] Fix | Delete
end
[270] Fix | Delete
end
[271] Fix | Delete
module_function :rmdir
[272] Fix | Delete
[273] Fix | Delete
#
[274] Fix | Delete
# :call-seq:
[275] Fix | Delete
# FileUtils.ln(target, link, force: nil, noop: nil, verbose: nil)
[276] Fix | Delete
# FileUtils.ln(target, dir, force: nil, noop: nil, verbose: nil)
[277] Fix | Delete
# FileUtils.ln(targets, dir, force: nil, noop: nil, verbose: nil)
[278] Fix | Delete
#
[279] Fix | Delete
# In the first form, creates a hard link +link+ which points to +target+.
[280] Fix | Delete
# If +link+ already exists, raises Errno::EEXIST.
[281] Fix | Delete
# But if the +force+ option is set, overwrites +link+.
[282] Fix | Delete
#
[283] Fix | Delete
# FileUtils.ln 'gcc', 'cc', verbose: true
[284] Fix | Delete
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
[285] Fix | Delete
#
[286] Fix | Delete
# In the second form, creates a link +dir/target+ pointing to +target+.
[287] Fix | Delete
# In the third form, creates several hard links in the directory +dir+,
[288] Fix | Delete
# pointing to each item in +targets+.
[289] Fix | Delete
# If +dir+ is not a directory, raises Errno::ENOTDIR.
[290] Fix | Delete
#
[291] Fix | Delete
# FileUtils.cd '/sbin'
[292] Fix | Delete
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
[293] Fix | Delete
#
[294] Fix | Delete
def ln(src, dest, force: nil, noop: nil, verbose: nil)
[295] Fix | Delete
fu_output_message "ln#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
[296] Fix | Delete
return if noop
[297] Fix | Delete
fu_each_src_dest0(src, dest) do |s,d|
[298] Fix | Delete
remove_file d, true if force
[299] Fix | Delete
File.link s, d
[300] Fix | Delete
end
[301] Fix | Delete
end
[302] Fix | Delete
module_function :ln
[303] Fix | Delete
[304] Fix | Delete
alias link ln
[305] Fix | Delete
module_function :link
[306] Fix | Delete
[307] Fix | Delete
#
[308] Fix | Delete
# Hard link +src+ to +dest+. If +src+ is a directory, this method links
[309] Fix | Delete
# all its contents recursively. If +dest+ is a directory, links
[310] Fix | Delete
# +src+ to +dest/src+.
[311] Fix | Delete
#
[312] Fix | Delete
# +src+ can be a list of files.
[313] Fix | Delete
#
[314] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[315] Fix | Delete
#
[316] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[317] Fix | Delete
#
[318] Fix | Delete
# FileUtils.rm_r site_ruby + '/mylib', force: true
[319] Fix | Delete
# FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
[320] Fix | Delete
#
[321] Fix | Delete
# # Examples of linking several files to target directory.
[322] Fix | Delete
# FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
[323] Fix | Delete
# FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true
[324] Fix | Delete
#
[325] Fix | Delete
# # If you want to link all contents of a directory instead of the
[326] Fix | Delete
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
[327] Fix | Delete
# # use the following code.
[328] Fix | Delete
# FileUtils.cp_lr 'src/.', 'dest' # cp_lr('src', 'dest') makes dest/src, but this doesn't.
[329] Fix | Delete
#
[330] Fix | Delete
def cp_lr(src, dest, noop: nil, verbose: nil,
[331] Fix | Delete
dereference_root: true, remove_destination: false)
[332] Fix | Delete
fu_output_message "cp -lr#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
[333] Fix | Delete
return if noop
[334] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[335] Fix | Delete
link_entry s, d, dereference_root, remove_destination
[336] Fix | Delete
end
[337] Fix | Delete
end
[338] Fix | Delete
module_function :cp_lr
[339] Fix | Delete
[340] Fix | Delete
#
[341] Fix | Delete
# :call-seq:
[342] Fix | Delete
# FileUtils.ln_s(target, link, force: nil, noop: nil, verbose: nil)
[343] Fix | Delete
# FileUtils.ln_s(target, dir, force: nil, noop: nil, verbose: nil)
[344] Fix | Delete
# FileUtils.ln_s(targets, dir, force: nil, noop: nil, verbose: nil)
[345] Fix | Delete
#
[346] Fix | Delete
# In the first form, creates a symbolic link +link+ which points to +target+.
[347] Fix | Delete
# If +link+ already exists, raises Errno::EEXIST.
[348] Fix | Delete
# But if the <tt>force</tt> option is set, overwrites +link+.
[349] Fix | Delete
#
[350] Fix | Delete
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
[351] Fix | Delete
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
[352] Fix | Delete
#
[353] Fix | Delete
# In the second form, creates a link +dir/target+ pointing to +target+.
[354] Fix | Delete
# In the third form, creates several symbolic links in the directory +dir+,
[355] Fix | Delete
# pointing to each item in +targets+.
[356] Fix | Delete
# If +dir+ is not a directory, raises Errno::ENOTDIR.
[357] Fix | Delete
#
[358] Fix | Delete
# FileUtils.ln_s Dir.glob('/bin/*.rb'), '/home/foo/bin'
[359] Fix | Delete
#
[360] Fix | Delete
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
[361] Fix | Delete
fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
[362] Fix | Delete
return if noop
[363] Fix | Delete
fu_each_src_dest0(src, dest) do |s,d|
[364] Fix | Delete
remove_file d, true if force
[365] Fix | Delete
File.symlink s, d
[366] Fix | Delete
end
[367] Fix | Delete
end
[368] Fix | Delete
module_function :ln_s
[369] Fix | Delete
[370] Fix | Delete
alias symlink ln_s
[371] Fix | Delete
module_function :symlink
[372] Fix | Delete
[373] Fix | Delete
#
[374] Fix | Delete
# :call-seq:
[375] Fix | Delete
# FileUtils.ln_sf(*args)
[376] Fix | Delete
#
[377] Fix | Delete
# Same as
[378] Fix | Delete
#
[379] Fix | Delete
# FileUtils.ln_s(*args, force: true)
[380] Fix | Delete
#
[381] Fix | Delete
def ln_sf(src, dest, noop: nil, verbose: nil)
[382] Fix | Delete
ln_s src, dest, force: true, noop: noop, verbose: verbose
[383] Fix | Delete
end
[384] Fix | Delete
module_function :ln_sf
[385] Fix | Delete
[386] Fix | Delete
#
[387] Fix | Delete
# Hard links a file system entry +src+ to +dest+.
[388] Fix | Delete
# If +src+ is a directory, this method links its contents recursively.
[389] Fix | Delete
#
[390] Fix | Delete
# Both of +src+ and +dest+ must be a path name.
[391] Fix | Delete
# +src+ must exist, +dest+ must not exist.
[392] Fix | Delete
#
[393] Fix | Delete
# If +dereference_root+ is true, this method dereferences the tree root.
[394] Fix | Delete
#
[395] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[396] Fix | Delete
#
[397] Fix | Delete
def link_entry(src, dest, dereference_root = false, remove_destination = false)
[398] Fix | Delete
Entry_.new(src, nil, dereference_root).traverse do |ent|
[399] Fix | Delete
destent = Entry_.new(dest, ent.rel, false)
[400] Fix | Delete
File.unlink destent.path if remove_destination && File.file?(destent.path)
[401] Fix | Delete
ent.link destent.path
[402] Fix | Delete
end
[403] Fix | Delete
end
[404] Fix | Delete
module_function :link_entry
[405] Fix | Delete
[406] Fix | Delete
#
[407] Fix | Delete
# Copies a file content +src+ to +dest+. If +dest+ is a directory,
[408] Fix | Delete
# copies +src+ to +dest/src+.
[409] Fix | Delete
#
[410] Fix | Delete
# If +src+ is a list of files, then +dest+ must be a directory.
[411] Fix | Delete
#
[412] Fix | Delete
# FileUtils.cp 'eval.c', 'eval.c.org'
[413] Fix | Delete
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
[414] Fix | Delete
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true
[415] Fix | Delete
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
[416] Fix | Delete
#
[417] Fix | Delete
def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
[418] Fix | Delete
fu_output_message "cp#{preserve ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if verbose
[419] Fix | Delete
return if noop
[420] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[421] Fix | Delete
copy_file s, d, preserve
[422] Fix | Delete
end
[423] Fix | Delete
end
[424] Fix | Delete
module_function :cp
[425] Fix | Delete
[426] Fix | Delete
alias copy cp
[427] Fix | Delete
module_function :copy
[428] Fix | Delete
[429] Fix | Delete
#
[430] Fix | Delete
# Copies +src+ to +dest+. If +src+ is a directory, this method copies
[431] Fix | Delete
# all its contents recursively. If +dest+ is a directory, copies
[432] Fix | Delete
# +src+ to +dest/src+.
[433] Fix | Delete
#
[434] Fix | Delete
# +src+ can be a list of files.
[435] Fix | Delete
#
[436] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[437] Fix | Delete
#
[438] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[439] Fix | Delete
#
[440] Fix | Delete
# # Installing Ruby library "mylib" under the site_ruby
[441] Fix | Delete
# FileUtils.rm_r site_ruby + '/mylib', force: true
[442] Fix | Delete
# FileUtils.cp_r 'lib/', site_ruby + '/mylib'
[443] Fix | Delete
#
[444] Fix | Delete
# # Examples of copying several files to target directory.
[445] Fix | Delete
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
[446] Fix | Delete
# FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true
[447] Fix | Delete
#
[448] Fix | Delete
# # If you want to copy all contents of a directory instead of the
[449] Fix | Delete
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
[450] Fix | Delete
# # use following code.
[451] Fix | Delete
# FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes dest/src,
[452] Fix | Delete
# # but this doesn't.
[453] Fix | Delete
#
[454] Fix | Delete
def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
[455] Fix | Delete
dereference_root: true, remove_destination: nil)
[456] Fix | Delete
fu_output_message "cp -r#{preserve ? 'p' : ''}#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
[457] Fix | Delete
return if noop
[458] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[459] Fix | Delete
copy_entry s, d, preserve, dereference_root, remove_destination
[460] Fix | Delete
end
[461] Fix | Delete
end
[462] Fix | Delete
module_function :cp_r
[463] Fix | Delete
[464] Fix | Delete
#
[465] Fix | Delete
# Copies a file system entry +src+ to +dest+.
[466] Fix | Delete
# If +src+ is a directory, this method copies its contents recursively.
[467] Fix | Delete
# This method preserves file types, c.f. symlink, directory...
[468] Fix | Delete
# (FIFO, device files and etc. are not supported yet)
[469] Fix | Delete
#
[470] Fix | Delete
# Both of +src+ and +dest+ must be a path name.
[471] Fix | Delete
# +src+ must exist, +dest+ must not exist.
[472] Fix | Delete
#
[473] Fix | Delete
# If +preserve+ is true, this method preserves owner, group, and
[474] Fix | Delete
# modified time. Permissions are copied regardless +preserve+.
[475] Fix | Delete
#
[476] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[477] Fix | Delete
#
[478] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[479] Fix | Delete
#
[480] Fix | Delete
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
[481] Fix | Delete
if dereference_root
[482] Fix | Delete
src = File.realpath(src)
[483] Fix | Delete
end
[484] Fix | Delete
[485] Fix | Delete
Entry_.new(src, nil, false).wrap_traverse(proc do |ent|
[486] Fix | Delete
destent = Entry_.new(dest, ent.rel, false)
[487] Fix | Delete
File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
[488] Fix | Delete
ent.copy destent.path
[489] Fix | Delete
end, proc do |ent|
[490] Fix | Delete
destent = Entry_.new(dest, ent.rel, false)
[491] Fix | Delete
ent.copy_metadata destent.path if preserve
[492] Fix | Delete
end)
[493] Fix | Delete
end
[494] Fix | Delete
module_function :copy_entry
[495] Fix | Delete
[496] Fix | Delete
#
[497] Fix | Delete
# Copies file contents of +src+ to +dest+.
[498] Fix | Delete
# Both of +src+ and +dest+ must be a path name.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function