[前][次][番号順一覧][スレッド一覧]

ruby-changes:19676

From: nobu <ko1@a...>
Date: Wed, 25 May 2011 07:12:28 +0900 (JST)
Subject: [ruby-changes:19676] nobu:r31721 (trunk): * lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.

nobu	2011-05-25 07:12:20 +0900 (Wed, 25 May 2011)

  New Revision: 31721

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31721

  Log:
    * lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.

  Modified files:
    trunk/ChangeLog
    trunk/lib/tempfile.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31720)
+++ ChangeLog	(revision 31721)
@@ -1,3 +1,7 @@
+Wed May 25 07:12:16 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.
+
 Tue May 24 17:30:36 2011  NARUSE, Yui  <naruse@r...>
 
 	* spec/README: fix typo.
Index: lib/tempfile.rb
===================================================================
--- lib/tempfile.rb	(revision 31720)
+++ lib/tempfile.rb	(revision 31721)
@@ -132,7 +132,6 @@
     ObjectSpace.define_finalizer(self, @clean_proc)
 
     create(basename, *rest) do |tmpname, n, opts|
-      lock = tmpname + '.lock'
       mode = File::RDWR|File::CREAT|File::EXCL
       perm = 0600
       if opts
@@ -142,12 +141,12 @@
       else
         opts = perm
       end
-      self.class.mkdir(lock)
+      lock = self.class.lock_tempfile(tmpname)
       begin
         @data[1] = @tmpfile = File.open(tmpname, mode, opts)
         @data[0] = @tmpname = tmpname
       ensure
-        self.class.rmdir(lock)
+        self.class.unlock_tempfile(lock)
       end
       @mode = mode & ~(File::CREAT|File::EXCL)
       perm or opts.freeze
@@ -328,12 +327,16 @@
 
     # :stopdoc:
 
-    def mkdir(*args)
-      Dir.mkdir(*args)
+    # makes lock for +tmpname+ and returns the lock.
+    def lock_tempfile(tmpname)
+      lock = tmpname + '.lock'
+      Dir.mkdir(lock)
+      lock
     end
 
-    def rmdir(*args)
-      Dir.rmdir(*args)
+    # unlock the lock made by _lock_tempfile_.
+    def unlock_tempfile(lock)
+      Dir.rmdir(lock)
     end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]