* lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
18684395c6
commit
9a7e295255
@ -1,3 +1,7 @@
|
|||||||
|
Wed May 25 07:12:16 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.
|
||||||
|
|
||||||
Tue May 24 17:30:36 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
Tue May 24 17:30:36 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* spec/README: fix typo.
|
* spec/README: fix typo.
|
||||||
|
@ -132,7 +132,6 @@ class Tempfile < DelegateClass(File)
|
|||||||
ObjectSpace.define_finalizer(self, @clean_proc)
|
ObjectSpace.define_finalizer(self, @clean_proc)
|
||||||
|
|
||||||
create(basename, *rest) do |tmpname, n, opts|
|
create(basename, *rest) do |tmpname, n, opts|
|
||||||
lock = tmpname + '.lock'
|
|
||||||
mode = File::RDWR|File::CREAT|File::EXCL
|
mode = File::RDWR|File::CREAT|File::EXCL
|
||||||
perm = 0600
|
perm = 0600
|
||||||
if opts
|
if opts
|
||||||
@ -142,12 +141,12 @@ class Tempfile < DelegateClass(File)
|
|||||||
else
|
else
|
||||||
opts = perm
|
opts = perm
|
||||||
end
|
end
|
||||||
self.class.mkdir(lock)
|
lock = self.class.lock_tempfile(tmpname)
|
||||||
begin
|
begin
|
||||||
@data[1] = @tmpfile = File.open(tmpname, mode, opts)
|
@data[1] = @tmpfile = File.open(tmpname, mode, opts)
|
||||||
@data[0] = @tmpname = tmpname
|
@data[0] = @tmpname = tmpname
|
||||||
ensure
|
ensure
|
||||||
self.class.rmdir(lock)
|
self.class.unlock_tempfile(lock)
|
||||||
end
|
end
|
||||||
@mode = mode & ~(File::CREAT|File::EXCL)
|
@mode = mode & ~(File::CREAT|File::EXCL)
|
||||||
perm or opts.freeze
|
perm or opts.freeze
|
||||||
@ -328,12 +327,16 @@ class Tempfile < DelegateClass(File)
|
|||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
|
||||||
def mkdir(*args)
|
# makes lock for +tmpname+ and returns the lock.
|
||||||
Dir.mkdir(*args)
|
def lock_tempfile(tmpname)
|
||||||
|
lock = tmpname + '.lock'
|
||||||
|
Dir.mkdir(lock)
|
||||||
|
lock
|
||||||
end
|
end
|
||||||
|
|
||||||
def rmdir(*args)
|
# unlock the lock made by _lock_tempfile_.
|
||||||
Dir.rmdir(*args)
|
def unlock_tempfile(lock)
|
||||||
|
Dir.rmdir(lock)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user