[#9722] Kernel#system broken inside Dir.chdir(&block) if system command doesn't have shell characters — <noreply@...>

Bugs item #7278, was opened at 2006-12-14 13:59

8 messages 2006/12/14

[#9749] System V IPC in standard library? — Steven Jenkins <steven.jenkins@...>

Back in August, I needed a semaphore to serialize access to an external

14 messages 2006/12/19

[#9753] CVS freeze — SASADA Koichi <ko1@...>

Hi,

20 messages 2006/12/20
[#9755] Re: [ruby-dev:30039] CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

[#9757] Re: [ruby-dev:30040] Re: CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

[PATCH] File.syscopy: close from if open on to fails

From: Matthias Lederhofer <matled@...>
Date: 2006-12-11 18:45:34 UTC
List: ruby-core #9701
File.syscopy did not close from if open on to failed.  The garbage
collector seems to take care of this after a while.  This patch should
not change the semantics of the function.

I have two additional questions about this method:
 1. Why does the function return false if syswrite/sysread fail but
    throws an exception on any other error?
 2. Shouldn't open(to) already get the permissions from the old file
    if the file does not exist?  Copying a non-world-readable file
    with this method may expose it during copying even though it gets
    stricter permissions after copying.

PS: Can I post something like this without subscribing to the mailing
list?

---
 lib/ftools.rb |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/lib/ftools.rb b/lib/ftools.rb
index 5f08233..fd9dbcf 100644
--- a/lib/ftools.rb
+++ b/lib/ftools.rb
@@ -57,25 +57,26 @@ class << File
     to = catname(from, to)
 
     fmode = stat(from).mode
-    tpath = to
-    not_exist = !exist?(tpath)
-
-    from = open(from, "rb")
-    to = open(to, "wb")
+    not_exist = !exist?(to)
 
     begin
-      while true
-	to.syswrite from.sysread(BUFSIZE)
+      ffile = open(from, "rb")
+      tfile = open(to, "wb")
+
+      begin
+	while true
+	  tfile.syswrite ffile.sysread(BUFSIZE)
+	end
+      rescue EOFError
+	ret = true
+      rescue
+	ret = false
       end
-    rescue EOFError
-      ret = true
-    rescue
-      ret = false
     ensure
-      to.close
-      from.close
+      tfile.close if tfile
+      ffile.close if ffile
     end
-    chmod(fmode, tpath) if not_exist
+    chmod(fmode, to) if not_exist
     ret
   end
 
-- 
1.4.4.1


In This Thread

Prev Next