* 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:
parent
5d8187d772
commit
15dabe8216
@ -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>
|
Sat Mar 3 15:52:26 2007 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* object.c (instance_variable_get): Restore rdoc markups lost in
|
* object.c (instance_variable_get): Restore rdoc markups lost in
|
||||||
|
11
file.c
11
file.c
@ -1989,13 +1989,16 @@ static VALUE
|
|||||||
rb_file_s_utime(int argc, VALUE *argv)
|
rb_file_s_utime(int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
VALUE atime, mtime, rest;
|
VALUE atime, mtime, rest;
|
||||||
struct timeval tvp[2];
|
struct timeval tvs[2], *tvp = NULL;
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
||||||
|
|
||||||
tvp[0] = rb_time_timeval(atime);
|
if (!NIL_P(atime) || !NIL_P(mtime)) {
|
||||||
tvp[1] = rb_time_timeval(mtime);
|
tvp = tvs;
|
||||||
|
tvp[0] = rb_time_timeval(atime);
|
||||||
|
tvp[1] = rb_time_timeval(mtime);
|
||||||
|
}
|
||||||
|
|
||||||
n = apply2files(utime_internal, rest, tvp);
|
n = apply2files(utime_internal, rest, tvp);
|
||||||
return LONG2FIX(n);
|
return LONG2FIX(n);
|
||||||
@ -2024,7 +2027,7 @@ rb_file_s_utime(int argc, VALUE *argv)
|
|||||||
VALUE atime, mtime, rest;
|
VALUE atime, mtime, rest;
|
||||||
long n;
|
long n;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct utimbuf utbuf;
|
struct utimbuf utbuf, *utp = NULL;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
||||||
|
|
||||||
|
@ -1007,22 +1007,33 @@ module FileUtils
|
|||||||
def touch(list, options = {})
|
def touch(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['touch']
|
fu_check_options options, OPT_TABLE['touch']
|
||||||
list = fu_list(list)
|
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]
|
return if options[:noop]
|
||||||
t = Time.now
|
|
||||||
list.each do |path|
|
list.each do |path|
|
||||||
|
created = nocreate
|
||||||
begin
|
begin
|
||||||
File.utime(t, t, path)
|
File.utime(t, t, path)
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
|
raise if created
|
||||||
File.open(path, 'a') {
|
File.open(path, 'a') {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
created = true
|
||||||
|
retry if t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
module_function :touch
|
module_function :touch
|
||||||
|
|
||||||
OPT_TABLE['touch'] = [:noop, :verbose]
|
OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate]
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
#define RUBY_RELEASE_MONTH 3
|
#define RUBY_RELEASE_MONTH 3
|
||||||
#define RUBY_RELEASE_DAY 3
|
#define RUBY_RELEASE_DAY 3
|
||||||
|
|
||||||
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
RUBY_EXTERN const char ruby_release_date[];
|
RUBY_EXTERN const char ruby_release_date[];
|
||||||
RUBY_EXTERN const char ruby_platform[];
|
RUBY_EXTERN const char ruby_platform[];
|
||||||
RUBY_EXTERN const int ruby_patchlevel;
|
RUBY_EXTERN const int ruby_patchlevel;
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user