* 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/trunk@11973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-03-03 13:37:02 +00:00
parent 5d8187d772
commit 15dabe8216
4 changed files with 30 additions and 7 deletions

View File

@ -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 15:52:26 2007 Akinori MUSHA <knu@iDaemons.org>
* object.c (instance_variable_get): Restore rdoc markups lost in

11
file.c
View File

@ -1989,13 +1989,16 @@ static VALUE
rb_file_s_utime(int argc, 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);
@ -2024,7 +2027,7 @@ rb_file_s_utime(int argc, VALUE *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);

View File

@ -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

View File

@ -11,7 +11,9 @@
#define RUBY_RELEASE_MONTH 3
#define RUBY_RELEASE_DAY 3
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];
RUBY_EXTERN const char ruby_release_date[];
RUBY_EXTERN const char ruby_platform[];
RUBY_EXTERN const int ruby_patchlevel;
#endif