* lib/fileutils.rb (install): support preserve timestamp.

* instruby.rb (install): use FileUtils::install preserve mode.

* lib/un.rb: new.  % ruby -run -e cp -- -p foo bar

* lib/mkmf.rb: use un.rb instead of ftools.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eban 2003-07-29 10:24:28 +00:00
Родитель 23301726b0
Коммит 3fbbec0c39
5 изменённых файлов: 123 добавлений и 14 удалений

Просмотреть файл

@ -1,3 +1,13 @@
Tue Jul 29 19:20:34 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/fileutils.rb (install): support preserve timestamp.
* instruby.rb (install): use FileUtils::install preserve mode.
* lib/un.rb: new. % ruby -run -e cp -- -p foo bar
* lib/mkmf.rb: use un.rb instead of ftools.rb.
Tue Jul 29 18:55:22 2003 Minero Aoki <aamine@loveruby.net>
* lib/net/smtp.rb: unify coding style.

Просмотреть файл

@ -55,12 +55,8 @@ include FileUtils::NoWrite if $dryrun
@fileutils_label = ''
def install(src, dest, options = {})
options[:preserve] = true
super
return if options[:noop]
fu_each_src_dest(src, dest) do |s, d|
st = File.stat(s)
File.utime(st.atime, st.mtime, d)
end
end
$made_dirs = {}

Просмотреть файл

@ -633,15 +633,17 @@ module FileUtils
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
#
def install( src, dest, options = {} )
fu_check_options options, :mode, :noop, :verbose
fu_output_message "install -c#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
fu_check_options options, :mode, :preserve, :noop, :verbose
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
return if options[:noop]
fu_each_src_dest(src, dest) do |s,d|
unless FileTest.exist?(d) and compare_file(s,d)
remove_file d, true
copy_file s, d
File.chmod options[:mode], d if options[:mode]
fu_preserve_attr(options[:preserve], s, d) {
remove_file d, true
copy_file s, d
}
File.chmod options[:mode], d if options[:mode]
end
end
end

Просмотреть файл

@ -662,10 +662,10 @@ arch = #{CONFIG['arch']}
sitearch = #{CONFIG['sitearch']}
ruby_version = #{Config::CONFIG['ruby_version']}
RUBY = #{$ruby}
RM = $(RUBY) -rftools -e "File::rm_f(*ARGV.map do|x|Dir[x]end.flatten.uniq)"
MAKEDIRS = $(RUBY) -r ftools -e 'File::makedirs(*ARGV)'
INSTALL_PROG = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0755, true)'
INSTALL_DATA = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)'
RM = $(RUBY) -run -e rm -- -f
MAKEDIRS = $(RUBY) -run -e mkdir -- -p
INSTALL_PROG = $(RUBY) -run -e install -- -vpm 0755
INSTALL_DATA = $(RUBY) -run -e install -- -vpm 0644
#### End of system configuration section. ####

101
lib/un.rb Normal file
Просмотреть файл

@ -0,0 +1,101 @@
require 'fileutils'
require 'getopts'
module FileUtils
# @fileutils_label = ''
@fileutils_output = $stdout
end
def setup(options = "")
options += "v"
ARGV.map! do |x|
case x
when /^-/
x.delete "^-#{options}"
when /[*?\[{]/
Dir[x]
else
x
end
end
ARGV.flatten!
ARGV.delete_if{|x| x == '-'}
getopts(options)
options = {}
options[:verbose] = true if $OPT["v"]
options[:force] = true if $OPT["f"]
options[:preserve] = true if $OPT["p"]
yield ARGV, options, $OPT
end
def mkdir
setup("p") do |argv, options, opt|
cmd = "mkdir"
cmd += "_p" if options.delete :preserve
FileUtils.send cmd, argv, options
end
end
def rmdir
setup do |argv, options|
FileUtils.rmdir argv, options
end
end
def ln
setup("sf") do |argv, options, opt|
cmd = "ln"
cmd += "_s" if opt["s"]
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.send cmd, argv, dest, options
end
end
def cp
setup("pr") do |argv, options, opt|
cmd = "cp"
cmd += "_r" if opt["r"]
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.send cmd, argv, dest, options
end
end
def mv
setup do |argv, options|
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.mv argv, dest, options
end
end
def rm
setup("fr") do |argv, options, opt|
cmd = "rm"
cmd += "_r" if opt["r"]
FileUtils.send cmd, argv, options
end
end
def install
setup("pm:") do |argv, options, opt|
options[:mode] = opt["m"] ? opt["m"].oct : 0755
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.install argv, dest, options
end
end
def chmod
setup do |argv, options|
mode = argv.shift.oct
FileUtils.chmod mode, argv, options
end
end
def touch
setup do |argv, options|
FileUtils.touch argv, options
end
end