diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-03 13:37:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-03 13:37:02 +0000 |
commit | 566b460705d0b58d0e5288dc73cfb80a59ace26e (patch) | |
tree | 79ce08b67c9a883ba54904b0887924293ab76b33 | |
parent | 44a1d06e1af5dc1e734a7201c33b17304cba2296 (diff) |
* 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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | file.c | 11 | ||||
-rw-r--r-- | lib/fileutils.rb | 17 |
3 files changed, 28 insertions, 7 deletions
@@ -1,3 +1,10 @@ +Sat Mar 3 22:37:02 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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] + Sat Mar 3 21:17:35 2007 Akinori MUSHA <knu@iDaemons.org> * eval.c (stack_check): Unset inline to fix build with GCC 3.4.6; @@ -2008,13 +2008,16 @@ rb_file_s_utime(argc, argv) VALUE *argv; { VALUE atime, mtime, rest; - struct timeval tvp[2]; + struct timeval tvs[2], *tvp = NULL; long n; rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest); - tvp[0] = rb_time_timeval(atime); - tvp[1] = rb_time_timeval(mtime); + if (!NIL_P(atime) || !NIL_P(mtime)) { + tvp = tvs; + tvp[0] = rb_time_timeval(atime); + tvp[1] = rb_time_timeval(mtime); + } n = apply2files(utime_internal, rest, tvp); return LONG2FIX(n); @@ -2047,7 +2050,7 @@ rb_file_s_utime(argc, argv) VALUE atime, mtime, rest; long n; struct timeval tv; - struct utimbuf utbuf; + struct utimbuf utbuf, *utp = NULL; rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest); diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 9aea507a19..9216c7477b 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1013,22 +1013,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 |