diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-04 14:51:31 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-04 14:51:31 +0000 |
| commit | 21a335d4459f5f438e4b1e538fa6d436c059a61d (patch) | |
| tree | ba8bc311178c8794ec70358521595fe9ce876fda /lib/fileutils.rb | |
| parent | 72f0530ce02774386acb608d0aef1d615ef7385e (diff) | |
| download | ruby-21a335d4459f5f438e4b1e538fa6d436c059a61d.tar.gz ruby-21a335d4459f5f438e4b1e538fa6d436c059a61d.tar.xz ruby-21a335d4459f5f438e4b1e538fa6d436c059a61d.zip | |
* 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/branches/ruby_1_8_6@11987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/fileutils.rb')
| -rw-r--r-- | lib/fileutils.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 9aea507a1..9216c7477 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 |
