2018ǯ89() 11:14 <normal / ruby-lang.org>:
>
> normal  2018-08-09 11:14:27 +0900 (Thu, 09 Aug 2018)
>
>   New Revision: 64238
>
>   https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64238
>
>   Log:
>     test/lib/leakchecker.rb (find_tempfiles): don't warn for missing files
>
>     Quiet a false-positive warning from TestHtgroup#test_htgroup

I think it is not a good idea because Tempfile still invokes unlink system call
on the missing file.
It is better to avoid such file operation in /tmp.

For example, following patch changes Tempfile.new to Tempfile.create to
avoid unnecessary unlink.

--- lib/webrick/httpauth/htgroup.rb 2018-08-13 02:20:27.168767081 +0900
+++ lib/webrick/httpauth/htgroup.rb+ 2018-08-13 02:20:24.548817671 +0900
@@ -63,16 +63,20 @@

       def flush(output=nil)
         output ||= @path
-        tmp = Tempfile.new("htgroup", File::dirname(output))
+        tmp = Tempfile.create("htgroup", File::dirname(output))
         begin
           @group.keys.sort.each{|group|
             tmp.puts(format("%s: %s", group, self.members(group).join(" ")))
           }
+        ensure
           tmp.close
-          File::rename(tmp.path, output)
-        rescue
-          tmp.close(true)
+          if $!
+            File.unlink(tmp.path)
+          else
+            File.rename(tmp.path, output)
+          end
         end
+        nil
       end

       ##

Note that this patch changes the return value of this method from 0 to nil.
-- 
Tanaka Akira

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>