Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby30/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.5.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
# optimize for the most common case
[213] Fix | Delete
begin
[214] Fix | Delete
fu_mkdir path, mode
[215] Fix | Delete
next
[216] Fix | Delete
rescue SystemCallError
[217] Fix | Delete
next if File.directory?(path)
[218] Fix | Delete
end
[219] Fix | Delete
[220] Fix | Delete
stack = []
[221] Fix | Delete
until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
[222] Fix | Delete
stack.push path
[223] Fix | Delete
path = File.dirname(path)
[224] Fix | Delete
break if File.directory?(path)
[225] Fix | Delete
end
[226] Fix | Delete
stack.pop if path == stack.last # root directory should exist
[227] Fix | Delete
stack.reverse_each do |dir|
[228] Fix | Delete
begin
[229] Fix | Delete
fu_mkdir dir, mode
[230] Fix | Delete
rescue SystemCallError
[231] Fix | Delete
raise unless File.directory?(dir)
[232] Fix | Delete
end
[233] Fix | Delete
end
[234] Fix | Delete
end
[235] Fix | Delete
[236] Fix | Delete
return *list
[237] Fix | Delete
end
[238] Fix | Delete
module_function :mkdir_p
[239] Fix | Delete
[240] Fix | Delete
alias mkpath mkdir_p
[241] Fix | Delete
alias makedirs mkdir_p
[242] Fix | Delete
module_function :mkpath
[243] Fix | Delete
module_function :makedirs
[244] Fix | Delete
[245] Fix | Delete
def fu_mkdir(path, mode) #:nodoc:
[246] Fix | Delete
path = remove_trailing_slash(path)
[247] Fix | Delete
if mode
[248] Fix | Delete
Dir.mkdir path, mode
[249] Fix | Delete
File.chmod mode, path
[250] Fix | Delete
else
[251] Fix | Delete
Dir.mkdir path
[252] Fix | Delete
end
[253] Fix | Delete
end
[254] Fix | Delete
private_module_function :fu_mkdir
[255] Fix | Delete
[256] Fix | Delete
#
[257] Fix | Delete
# Removes one or more directories.
[258] Fix | Delete
#
[259] Fix | Delete
# FileUtils.rmdir 'somedir'
[260] Fix | Delete
# FileUtils.rmdir %w(somedir anydir otherdir)
[261] Fix | Delete
# # Does not really remove directory; outputs message.
[262] Fix | Delete
# FileUtils.rmdir 'somedir', verbose: true, noop: true
[263] Fix | Delete
#
[264] Fix | Delete
def rmdir(list, parents: nil, noop: nil, verbose: nil)
[265] Fix | Delete
list = fu_list(list)
[266] Fix | Delete
fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if verbose
[267] Fix | Delete
return if noop
[268] Fix | Delete
list.each do |dir|
[269] Fix | Delete
Dir.rmdir(dir = remove_trailing_slash(dir))
[270] Fix | Delete
if parents
[271] Fix | Delete
begin
[272] Fix | Delete
until (parent = File.dirname(dir)) == '.' or parent == dir
[273] Fix | Delete
dir = parent
[274] Fix | Delete
Dir.rmdir(dir)
[275] Fix | Delete
end
[276] Fix | Delete
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
[277] Fix | Delete
end
[278] Fix | Delete
end
[279] Fix | Delete
end
[280] Fix | Delete
end
[281] Fix | Delete
module_function :rmdir
[282] Fix | Delete
[283] Fix | Delete
#
[284] Fix | Delete
# :call-seq:
[285] Fix | Delete
# FileUtils.ln(target, link, force: nil, noop: nil, verbose: nil)
[286] Fix | Delete
# FileUtils.ln(target, dir, force: nil, noop: nil, verbose: nil)
[287] Fix | Delete
# FileUtils.ln(targets, dir, force: nil, noop: nil, verbose: nil)
[288] Fix | Delete
#
[289] Fix | Delete
# In the first form, creates a hard link +link+ which points to +target+.
[290] Fix | Delete
# If +link+ already exists, raises Errno::EEXIST.
[291] Fix | Delete
# But if the +force+ option is set, overwrites +link+.
[292] Fix | Delete
#
[293] Fix | Delete
# FileUtils.ln 'gcc', 'cc', verbose: true
[294] Fix | Delete
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
[295] Fix | Delete
#
[296] Fix | Delete
# In the second form, creates a link +dir/target+ pointing to +target+.
[297] Fix | Delete
# In the third form, creates several hard links in the directory +dir+,
[298] Fix | Delete
# pointing to each item in +targets+.
[299] Fix | Delete
# If +dir+ is not a directory, raises Errno::ENOTDIR.
[300] Fix | Delete
#
[301] Fix | Delete
# FileUtils.cd '/sbin'
[302] Fix | Delete
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
[303] Fix | Delete
#
[304] Fix | Delete
def ln(src, dest, force: nil, noop: nil, verbose: nil)
[305] Fix | Delete
fu_output_message "ln#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
[306] Fix | Delete
return if noop
[307] Fix | Delete
fu_each_src_dest0(src, dest) do |s,d|
[308] Fix | Delete
remove_file d, true if force
[309] Fix | Delete
File.link s, d
[310] Fix | Delete
end
[311] Fix | Delete
end
[312] Fix | Delete
module_function :ln
[313] Fix | Delete
[314] Fix | Delete
alias link ln
[315] Fix | Delete
module_function :link
[316] Fix | Delete
[317] Fix | Delete
#
[318] Fix | Delete
# Hard link +src+ to +dest+. If +src+ is a directory, this method links
[319] Fix | Delete
# all its contents recursively. If +dest+ is a directory, links
[320] Fix | Delete
# +src+ to +dest/src+.
[321] Fix | Delete
#
[322] Fix | Delete
# +src+ can be a list of files.
[323] Fix | Delete
#
[324] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[325] Fix | Delete
#
[326] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[327] Fix | Delete
#
[328] Fix | Delete
# FileUtils.rm_r site_ruby + '/mylib', force: true
[329] Fix | Delete
# FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
[330] Fix | Delete
#
[331] Fix | Delete
# # Examples of linking several files to target directory.
[332] Fix | Delete
# FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
[333] Fix | Delete
# FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true
[334] Fix | Delete
#
[335] Fix | Delete
# # If you want to link all contents of a directory instead of the
[336] Fix | Delete
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
[337] Fix | Delete
# # use the following code.
[338] Fix | Delete
# FileUtils.cp_lr 'src/.', 'dest' # cp_lr('src', 'dest') makes dest/src, but this doesn't.
[339] Fix | Delete
#
[340] Fix | Delete
def cp_lr(src, dest, noop: nil, verbose: nil,
[341] Fix | Delete
dereference_root: true, remove_destination: false)
[342] Fix | Delete
fu_output_message "cp -lr#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
[343] Fix | Delete
return if noop
[344] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[345] Fix | Delete
link_entry s, d, dereference_root, remove_destination
[346] Fix | Delete
end
[347] Fix | Delete
end
[348] Fix | Delete
module_function :cp_lr
[349] Fix | Delete
[350] Fix | Delete
#
[351] Fix | Delete
# :call-seq:
[352] Fix | Delete
# FileUtils.ln_s(target, link, force: nil, noop: nil, verbose: nil)
[353] Fix | Delete
# FileUtils.ln_s(target, dir, force: nil, noop: nil, verbose: nil)
[354] Fix | Delete
# FileUtils.ln_s(targets, dir, force: nil, noop: nil, verbose: nil)
[355] Fix | Delete
#
[356] Fix | Delete
# In the first form, creates a symbolic link +link+ which points to +target+.
[357] Fix | Delete
# If +link+ already exists, raises Errno::EEXIST.
[358] Fix | Delete
# But if the <tt>force</tt> option is set, overwrites +link+.
[359] Fix | Delete
#
[360] Fix | Delete
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
[361] Fix | Delete
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
[362] Fix | Delete
#
[363] Fix | Delete
# In the second form, creates a link +dir/target+ pointing to +target+.
[364] Fix | Delete
# In the third form, creates several symbolic links in the directory +dir+,
[365] Fix | Delete
# pointing to each item in +targets+.
[366] Fix | Delete
# If +dir+ is not a directory, raises Errno::ENOTDIR.
[367] Fix | Delete
#
[368] Fix | Delete
# FileUtils.ln_s Dir.glob('/bin/*.rb'), '/home/foo/bin'
[369] Fix | Delete
#
[370] Fix | Delete
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
[371] Fix | Delete
fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
[372] Fix | Delete
return if noop
[373] Fix | Delete
fu_each_src_dest0(src, dest) do |s,d|
[374] Fix | Delete
remove_file d, true if force
[375] Fix | Delete
File.symlink s, d
[376] Fix | Delete
end
[377] Fix | Delete
end
[378] Fix | Delete
module_function :ln_s
[379] Fix | Delete
[380] Fix | Delete
alias symlink ln_s
[381] Fix | Delete
module_function :symlink
[382] Fix | Delete
[383] Fix | Delete
#
[384] Fix | Delete
# :call-seq:
[385] Fix | Delete
# FileUtils.ln_sf(*args)
[386] Fix | Delete
#
[387] Fix | Delete
# Same as
[388] Fix | Delete
#
[389] Fix | Delete
# FileUtils.ln_s(*args, force: true)
[390] Fix | Delete
#
[391] Fix | Delete
def ln_sf(src, dest, noop: nil, verbose: nil)
[392] Fix | Delete
ln_s src, dest, force: true, noop: noop, verbose: verbose
[393] Fix | Delete
end
[394] Fix | Delete
module_function :ln_sf
[395] Fix | Delete
[396] Fix | Delete
#
[397] Fix | Delete
# Hard links a file system entry +src+ to +dest+.
[398] Fix | Delete
# If +src+ is a directory, this method links its contents recursively.
[399] Fix | Delete
#
[400] Fix | Delete
# Both of +src+ and +dest+ must be a path name.
[401] Fix | Delete
# +src+ must exist, +dest+ must not exist.
[402] Fix | Delete
#
[403] Fix | Delete
# If +dereference_root+ is true, this method dereferences the tree root.
[404] Fix | Delete
#
[405] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[406] Fix | Delete
#
[407] Fix | Delete
def link_entry(src, dest, dereference_root = false, remove_destination = false)
[408] Fix | Delete
Entry_.new(src, nil, dereference_root).traverse do |ent|
[409] Fix | Delete
destent = Entry_.new(dest, ent.rel, false)
[410] Fix | Delete
File.unlink destent.path if remove_destination && File.file?(destent.path)
[411] Fix | Delete
ent.link destent.path
[412] Fix | Delete
end
[413] Fix | Delete
end
[414] Fix | Delete
module_function :link_entry
[415] Fix | Delete
[416] Fix | Delete
#
[417] Fix | Delete
# Copies a file content +src+ to +dest+. If +dest+ is a directory,
[418] Fix | Delete
# copies +src+ to +dest/src+.
[419] Fix | Delete
#
[420] Fix | Delete
# If +src+ is a list of files, then +dest+ must be a directory.
[421] Fix | Delete
#
[422] Fix | Delete
# FileUtils.cp 'eval.c', 'eval.c.org'
[423] Fix | Delete
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
[424] Fix | Delete
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true
[425] Fix | Delete
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
[426] Fix | Delete
#
[427] Fix | Delete
def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
[428] Fix | Delete
fu_output_message "cp#{preserve ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if verbose
[429] Fix | Delete
return if noop
[430] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[431] Fix | Delete
copy_file s, d, preserve
[432] Fix | Delete
end
[433] Fix | Delete
end
[434] Fix | Delete
module_function :cp
[435] Fix | Delete
[436] Fix | Delete
alias copy cp
[437] Fix | Delete
module_function :copy
[438] Fix | Delete
[439] Fix | Delete
#
[440] Fix | Delete
# Copies +src+ to +dest+. If +src+ is a directory, this method copies
[441] Fix | Delete
# all its contents recursively. If +dest+ is a directory, copies
[442] Fix | Delete
# +src+ to +dest/src+.
[443] Fix | Delete
#
[444] Fix | Delete
# +src+ can be a list of files.
[445] Fix | Delete
#
[446] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[447] Fix | Delete
#
[448] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[449] Fix | Delete
#
[450] Fix | Delete
# # Installing Ruby library "mylib" under the site_ruby
[451] Fix | Delete
# FileUtils.rm_r site_ruby + '/mylib', force: true
[452] Fix | Delete
# FileUtils.cp_r 'lib/', site_ruby + '/mylib'
[453] Fix | Delete
#
[454] Fix | Delete
# # Examples of copying several files to target directory.
[455] Fix | Delete
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
[456] Fix | Delete
# FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true
[457] Fix | Delete
#
[458] Fix | Delete
# # If you want to copy all contents of a directory instead of the
[459] Fix | Delete
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
[460] Fix | Delete
# # use following code.
[461] Fix | Delete
# FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes dest/src,
[462] Fix | Delete
# # but this doesn't.
[463] Fix | Delete
#
[464] Fix | Delete
def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
[465] Fix | Delete
dereference_root: true, remove_destination: nil)
[466] Fix | Delete
fu_output_message "cp -r#{preserve ? 'p' : ''}#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
[467] Fix | Delete
return if noop
[468] Fix | Delete
fu_each_src_dest(src, dest) do |s, d|
[469] Fix | Delete
copy_entry s, d, preserve, dereference_root, remove_destination
[470] Fix | Delete
end
[471] Fix | Delete
end
[472] Fix | Delete
module_function :cp_r
[473] Fix | Delete
[474] Fix | Delete
#
[475] Fix | Delete
# Copies a file system entry +src+ to +dest+.
[476] Fix | Delete
# If +src+ is a directory, this method copies its contents recursively.
[477] Fix | Delete
# This method preserves file types, c.f. symlink, directory...
[478] Fix | Delete
# (FIFO, device files and etc. are not supported yet)
[479] Fix | Delete
#
[480] Fix | Delete
# Both of +src+ and +dest+ must be a path name.
[481] Fix | Delete
# +src+ must exist, +dest+ must not exist.
[482] Fix | Delete
#
[483] Fix | Delete
# If +preserve+ is true, this method preserves owner, group, and
[484] Fix | Delete
# modified time. Permissions are copied regardless +preserve+.
[485] Fix | Delete
#
[486] Fix | Delete
# If +dereference_root+ is true, this method dereference tree root.
[487] Fix | Delete
#
[488] Fix | Delete
# If +remove_destination+ is true, this method removes each destination file before copy.
[489] Fix | Delete
#
[490] Fix | Delete
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
[491] Fix | Delete
if dereference_root
[492] Fix | Delete
src = File.realpath(src)
[493] Fix | Delete
end
[494] Fix | Delete
[495] Fix | Delete
Entry_.new(src, nil, false).wrap_traverse(proc do |ent|
[496] Fix | Delete
destent = Entry_.new(dest, ent.rel, false)
[497] Fix | Delete
File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
[498] Fix | Delete
ent.copy destent.path
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function