mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/fileutils.rb (fu_parseargs): reject illegal options correctly.
* lib/fileutils.rb (uptodate?): parameter declaration was wrong. * lib/fileutils.rb: change coding styles. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
888b9a9739
commit
585cf46325
2 changed files with 54 additions and 46 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,12 @@
|
||||||
|
Fri Dec 27 13:23:29 2002 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* lib/fileutils.rb (fu_parseargs): reject illegal options
|
||||||
|
correctly.
|
||||||
|
|
||||||
|
* lib/fileutils.rb (uptodate?): parameter declaration was wrong.
|
||||||
|
|
||||||
|
* lib/fileutils.rb: change coding styles.
|
||||||
|
|
||||||
Fri Dec 27 02:56:58 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Fri Dec 27 02:56:58 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* instruby.rb: check only `-' option, and use fileutils instead of
|
* instruby.rb: check only `-' option, and use fileutils instead of
|
||||||
|
@ -1081,7 +1090,7 @@ Thu Oct 17 19:17:56 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
Thu Oct 17 12:58:24 2002 Minero Aoki <aamine@loveruby.net>
|
Thu Oct 17 12:58:24 2002 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/fileutils.rb: stat.blksize might become 0/nil.
|
* lib/fileutils.rb: stat.blksize might be 0/nil.
|
||||||
|
|
||||||
* lib/fileutils.rb: change coding style.
|
* lib/fileutils.rb: change coding style.
|
||||||
|
|
||||||
|
|
|
@ -262,13 +262,13 @@ module FileUtils
|
||||||
alias chdir cd
|
alias chdir cd
|
||||||
|
|
||||||
|
|
||||||
def uptodate?( new, *args )
|
def uptodate?( new, old_list, *options )
|
||||||
verbose, = fu_parseargs(args, :verbose)
|
verbose, = fu_parseargs(options, :verbose)
|
||||||
fu_output_message "newest? #{args.join ' '}" if verbose
|
fu_output_message "uptodate? #{new} #{old_list.join ' '}" if verbose
|
||||||
|
|
||||||
return false unless FileTest.exist? new
|
return false unless FileTest.exist? new
|
||||||
new_time = File.ctime(new)
|
new_time = File.ctime(new)
|
||||||
args.each do |old|
|
old_list.each do |old|
|
||||||
if FileTest.exist? old
|
if FileTest.exist? old
|
||||||
return false unless new_time > File.mtime(old)
|
return false unless new_time > File.mtime(old)
|
||||||
end
|
end
|
||||||
|
@ -385,24 +385,23 @@ module FileUtils
|
||||||
end
|
end
|
||||||
|
|
||||||
def fu_copy_dir( src, dest, rel, preserve )
|
def fu_copy_dir( src, dest, rel, preserve )
|
||||||
fu_preserve_attr( preserve, "#{src}/#{rel}",
|
fu_preserve_attr(preserve, "#{src}/#{rel}", "#{dest}/#{rel}") {|s,d|
|
||||||
"#{dest}/#{rel}" ) {|s,d|
|
|
||||||
dir = File.expand_path(d) # to remove '/./'
|
dir = File.expand_path(d) # to remove '/./'
|
||||||
Dir.mkdir dir unless FileTest.directory? dir
|
Dir.mkdir dir unless FileTest.directory? dir
|
||||||
}
|
}
|
||||||
Dir.entries( "#{src}/#{rel}" ).each do |fn|
|
Dir.entries("#{src}/#{rel}").each do |fname|
|
||||||
if FileTest.directory? File.join(src,rel,fn)
|
if FileTest.directory? File.join(src,rel,fname)
|
||||||
next if /\A\.\.?\z/ === fn
|
next if /\A\.\.?\z/ === fname
|
||||||
fu_copy_dir src, dest, "#{rel}/#{fn}", preserve
|
fu_copy_dir src, dest, "#{rel}/#{fname}", preserve
|
||||||
else
|
else
|
||||||
fu_p_copy File.join(src,rel,fn), File.join(dest,rel,fn), preserve
|
fu_p_copy File.join(src,rel,fname), File.join(dest,rel,fname), preserve
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private :fu_copy_dir
|
private :fu_copy_dir
|
||||||
|
|
||||||
def fu_p_copy( src, dest, really )
|
def fu_p_copy( src, dest, really )
|
||||||
fu_preserve_attr( really, src, dest ) {
|
fu_preserve_attr(really, src, dest) {
|
||||||
copy_file src, dest
|
copy_file src, dest
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -523,22 +522,20 @@ module FileUtils
|
||||||
rm_r list, :force, *options
|
rm_r list, :force, *options
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_file( fn, force = false )
|
def remove_file( fname, force = false )
|
||||||
first = true
|
first_time_p = true
|
||||||
begin
|
begin
|
||||||
File.unlink fn
|
File.unlink fname
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
force or raise
|
raise unless force
|
||||||
rescue
|
rescue
|
||||||
# rescue dos?
|
if first_time_p
|
||||||
begin
|
# try once more for Windows
|
||||||
if first
|
first_time_p = false
|
||||||
first = false
|
File.chmod 0777, fname
|
||||||
File.chmod 0777, fn
|
retry
|
||||||
retry
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
end
|
end
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -546,14 +543,16 @@ module FileUtils
|
||||||
Dir.foreach(dir) do |file|
|
Dir.foreach(dir) do |file|
|
||||||
next if /\A\.\.?\z/ === file
|
next if /\A\.\.?\z/ === file
|
||||||
path = "#{dir}/#{file}"
|
path = "#{dir}/#{file}"
|
||||||
if FileTest.directory? path then remove_dir path, force
|
if FileTest.directory? path
|
||||||
else remove_file path, force
|
remove_dir path, force
|
||||||
|
else
|
||||||
|
remove_file path, force
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
Dir.rmdir dir
|
Dir.rmdir dir
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
force or raise
|
raise unless force
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -565,7 +564,7 @@ module FileUtils
|
||||||
sa = sb = nil
|
sa = sb = nil
|
||||||
st = File.stat(filea)
|
st = File.stat(filea)
|
||||||
bsize = fu_blksize(st.blksize)
|
bsize = fu_blksize(st.blksize)
|
||||||
File.size(fileb) == st.size or return true
|
return true unless File.size(fileb) == st.size
|
||||||
|
|
||||||
File.open(filea, 'rb') {|a|
|
File.open(filea, 'rb') {|a|
|
||||||
File.open(fileb, 'rb') {|b|
|
File.open(fileb, 'rb') {|b|
|
||||||
|
@ -591,10 +590,10 @@ module FileUtils
|
||||||
|
|
||||||
def install( src, dest, mode, *options )
|
def install( src, dest, mode, *options )
|
||||||
noop, verbose, = fu_parseargs(options, :noop, :verbose)
|
noop, verbose, = fu_parseargs(options, :noop, :verbose)
|
||||||
fu_output_message "install #{[src,dest].flatten.join ' '}#{mode ? ' %o'%mode : ''}" if verbose
|
fu_output_message "install#{mode ? ' %o'%mode : ''} #{[src,dest].flatten.join ' '}" if verbose
|
||||||
return if noop
|
return if noop
|
||||||
|
|
||||||
fu_each_src_dest( src, dest ) do |s,d|
|
fu_each_src_dest(src, dest) do |s,d|
|
||||||
unless FileTest.exist? d and cmp(s,d)
|
unless FileTest.exist? d and cmp(s,d)
|
||||||
remove_file d, true
|
remove_file d, true
|
||||||
copy_file s, d
|
copy_file s, d
|
||||||
|
@ -631,19 +630,19 @@ module FileUtils
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def fu_parseargs( opts, *flagdecl )
|
def fu_parseargs( optargs, *optdecl )
|
||||||
tab = {}
|
table = Hash.new(false)
|
||||||
if opts.last == true or opts.last == false
|
if optargs.last == true or optargs.last == false
|
||||||
tab[:verbose] = opts.pop
|
table[:verbose] = optargs.pop
|
||||||
end
|
end
|
||||||
while Symbol === opts.last
|
optargs.each do |opt|
|
||||||
tab[opts.pop] = true
|
table[opt] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
flags = flagdecl.collect {|s| tab.delete(s) }
|
option_list = optdecl.map {|s| table.delete(s) }
|
||||||
tab.empty? or raise ArgumentError, "wrong option :#{tab.keys.join(' :')}"
|
raise ArgumentError, "wrong option #{table.keys.map {|o|o.inspect}.join(' ')}" unless table.empty?
|
||||||
|
|
||||||
flags
|
option_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -658,8 +657,8 @@ module FileUtils
|
||||||
dir = dest
|
dir = dest
|
||||||
# FileTest.directory? dir or raise ArgumentError, "must be dir: #{dir}"
|
# FileTest.directory? dir or raise ArgumentError, "must be dir: #{dir}"
|
||||||
dir += (dir[-1,1] == '/') ? '' : '/'
|
dir += (dir[-1,1] == '/') ? '' : '/'
|
||||||
src.each do |fn|
|
src.each do |fname|
|
||||||
yield fn, dir + File.basename(fn)
|
yield fname, dir + File.basename(fname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -737,7 +736,7 @@ module FileUtils
|
||||||
|
|
||||||
FileUtils::OPT_TABLE.each do |name, opts|
|
FileUtils::OPT_TABLE.each do |name, opts|
|
||||||
next unless opts.include? 'verbose'
|
next unless opts.include? 'verbose'
|
||||||
module_eval <<-End, __FILE__, __LINE__ + 1
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
def #{name}( *args )
|
def #{name}( *args )
|
||||||
unless defined? @fileutils_verbose
|
unless defined? @fileutils_verbose
|
||||||
@fileutils_verbose = true
|
@fileutils_verbose = true
|
||||||
|
@ -763,7 +762,7 @@ module FileUtils
|
||||||
|
|
||||||
FileUtils::OPT_TABLE.each do |name, opts|
|
FileUtils::OPT_TABLE.each do |name, opts|
|
||||||
next unless opts.include? 'noop'
|
next unless opts.include? 'noop'
|
||||||
module_eval <<-End, __FILE__, __LINE__ + 1
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
def #{name}( *args )
|
def #{name}( *args )
|
||||||
unless defined? @fileutils_nowrite
|
unless defined? @fileutils_nowrite
|
||||||
@fileutils_nowrite = true
|
@fileutils_nowrite = true
|
||||||
|
@ -796,8 +795,8 @@ module FileUtils
|
||||||
attr_accessor :preserve
|
attr_accessor :preserve
|
||||||
|
|
||||||
FileUtils::OPT_TABLE.each do |name, opts|
|
FileUtils::OPT_TABLE.each do |name, opts|
|
||||||
s = opts.collect {|i| "args.unshift :#{i} if @#{i}" }.join(' '*10+"\n")
|
s = opts.map {|i| "args.unshift :#{i} if @#{i}" }.join(' '*10+"\n")
|
||||||
module_eval <<-End, __FILE__, __LINE__ + 1
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
def #{name}( *args )
|
def #{name}( *args )
|
||||||
#{s}
|
#{s}
|
||||||
super(*args)
|
super(*args)
|
||||||
|
|
Loading…
Reference in a new issue