From eaa3ffbae8f20ddae208747db5310b113ffbbf71 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 2 Jun 2008 09:51:30 +0000 Subject: * lib/un.rb (wait_writable): wait until target files can be written actually. * win32/Makefile.sub (LDSHARED_0, LINK_SO): get rid of failure of mt.exe. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/un.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib') diff --git a/lib/un.rb b/lib/un.rb index 9bf6c13146..4512c83181 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -213,6 +213,33 @@ def touch end end +## +# Wait until the file becomes writable. +# +# ruby -run -e wait_writable -- [OPTION] FILE +# + +def wait_writable + setup("n:w:v") do |argv, options| + verbose = options[:verbose] + n = options[:n] and n = Integer(n) + wait = (wait = options[:w]) ? Float(wait) : 0.2 + argv.each do |file| + begin + open(file, "r+b") + rescue Errno::ENOENT + break + rescue Errno::EACCES => e + raise if n and (n -= 1) <= 0 + puts e + STDOUT.flush + sleep wait + retry + end + end + end +end + ## # Display help message. # -- cgit v1.2.3