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