From 3fbbec0c39f5a166e3bd5016c6dfaf30c26bb498 Mon Sep 17 00:00:00 2001 From: eban Date: Tue, 29 Jul 2003 10:24:28 +0000 Subject: * 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 --- ChangeLog | 10 ++++++ instruby.rb | 6 +--- lib/fileutils.rb | 12 ++++--- lib/mkmf.rb | 8 ++--- lib/un.rb | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 lib/un.rb diff --git a/ChangeLog b/ChangeLog index 86eac1c503..86ad23a23b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Jul 29 19:20:34 2003 WATANABE Hirofumi + + * 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 * lib/net/smtp.rb: unify coding style. diff --git a/instruby.rb b/instruby.rb index 3b139941fe..f005597ae2 100644 --- a/instruby.rb +++ b/instruby.rb @@ -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 = {} diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 0efd204394..d6714229a9 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -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 diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 51eb169217..15325601eb 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -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. #### diff --git a/lib/un.rb b/lib/un.rb new file mode 100644 index 0000000000..3834784f2d --- /dev/null +++ b/lib/un.rb @@ -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 -- cgit v1.2.3