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