From db90961aa12b4c6939c8b63784df902bbf7a4927 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 3 Mar 2007 13:37:02 +0000 Subject: * file.c (rb_file_s_utime): allow nil to set the current time. * lib/fileutils.rb (touch): ditto, and added :mtime and :nocreate options. fixed: [ruby-talk:219037] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/fileutils.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 976b83883..4da9b56fb 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1007,22 +1007,33 @@ module FileUtils def touch(list, options = {}) fu_check_options options, OPT_TABLE['touch'] list = fu_list(list) - fu_output_message "touch #{list.join ' '}" if options[:verbose] + created = nocreate = options[:nocreate] + t = options[:mtime] + if options[:verbose] + fu_output_message "touch #{ + nocreate ? ' -c' : '' + }#{ + t ? t.strftime(' -t %Y%m%d%H%M.%S') : '' + }#{list.join ' '}" + end return if options[:noop] - t = Time.now list.each do |path| + created = nocreate begin File.utime(t, t, path) rescue Errno::ENOENT + raise if created File.open(path, 'a') { ; } + created = true + retry if t end end end module_function :touch - OPT_TABLE['touch'] = [:noop, :verbose] + OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate] private -- cgit