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