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