From: Daniel Berger Date: 2007-03-23T02:33:16+09:00 Subject: Re: [ ruby-Bugs-9470 ] TempFile fails to delete the file if inside a Dir.chdir block noreply@rubyforge.org wrote: > Bugs item #9470, was opened at 2007-03-22 16:28 > You can respond by visiting: > http://rubyforge.org/tracker/?func=detail&atid=1698&aid=9470&group_id=426 > > Category: Standard Library > Group: 1.8.5 > Status: Open > Resolution: None > Priority: 3 > Submitted By: Niko Vuokko (vulpes) > Assigned to: Nobody (None) > Summary: TempFile fails to delete the file if inside a Dir.chdir block > > Initial Comment: > Latest Cygwin with Ruby 1.8.5-3 on Win XP Pro SP 2. > > TempFile fails to delete the temporary file it creates, if working inside a Dir.chdir block: > > # Doesn't work > > Dir.chdir("./dir") do > Tempfile.open("johndoe", ".") {} > end > > > # These work fine > > Tempfile.open("./dir/johndoe", ".") {} > > Tempfile.open("dir/johndoe", ".") {} > > Tempfile.open("johndoe", "dir") {} I haven't thoroughly tested it, but I think this patch will do the trick: --- tempfile.orig Sun Jun 11 08:27:38 2006 +++ tempfile.rb Thu Mar 22 11:22:58 2007 @@ -24,6 +24,8 @@ def initialize(basename, tmpdir=Dir::tmpdir) if $SAFE > 0 and tmpdir.tainted? tmpdir = '/tmp' + else + tmpdir = File.expand_path(tmpdir) end lock = nil