summaryrefslogtreecommitdiff
path: root/lib/tempfile.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-05-06 15:06:00 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-05-06 15:06:00 +0000
commit1d3d27b42d1371ba6242ec217ca803f107ceb9eb (patch)
tree8d7e184fd63610124717df8dec31e719901965ad /lib/tempfile.rb
parent94df732f8b69356626130e0ec8b2dbc9340082ef (diff)
forgot some checkins.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r--lib/tempfile.rb49
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 0b22de2..d4876f9 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -4,7 +4,7 @@
# The class for temporary files.
# o creates a temporary file, which name is "basename.pid.n" with mode "w+".
# o Tempfile objects can be used like IO object.
-# o with tmpfile.close(true) created temporary files are removed.
+# o with tempfile.close(true) created temporary files are removed.
# o created files are also removed on script termination.
# o with Tempfile#open, you can reopen the temporary file.
# o file mode of the temporary files are 0600.
@@ -35,36 +35,31 @@ class Tempfile < SimpleDelegator
if $SAFE > 0 and tmpdir.tainted?
tmpdir = '/tmp'
end
- umask = File.umask(0177)
- begin
- n = 0
- while true
- begin
- tmpname = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)
- lock = tmpname + '.lock'
- unless File.exist?(tmpname) or File.exist?(lock)
- Dir.mkdir(lock)
- break
- end
- rescue
- raise "cannot generate tmpfile `%s'" % tmpname if n >= Max_try
- #sleep(1)
+ n = 0
+ while true
+ begin
+ tmpname = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)
+ lock = tmpname + '.lock'
+ unless File.exist?(tmpname) or File.exist?(lock)
+ Dir.mkdir(lock)
+ break
end
- n += 1
+ rescue
+ raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
+ #sleep(1)
end
+ n += 1
+ end
- @protect = []
- @clean_files = Tempfile.callback(tmpname, @protect)
- ObjectSpace.define_finalizer(self, @clean_files)
+ @protect = []
+ @clean_files = Tempfile.callback(tmpname, @protect)
+ ObjectSpace.define_finalizer(self, @clean_files)
- @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL)
- @protect[0] = @tmpfile
- @tmpname = tmpname
- super(@tmpfile)
- Dir.rmdir(lock)
- ensure
- File.umask(umask)
- end
+ @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL)
+ @protect[0] = @tmpfile
+ @tmpname = tmpname
+ super(@tmpfile)
+ Dir.rmdir(lock)
end
def Tempfile.open(*args)