Forum: Ruby Cygwin + TempFile + Dir.chdir = failure

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
17908c7c54cefa673d7cd2d6f2c3c8a5?d=identicon&s=25 vulpes (Guest)
on 2007-03-21 11:51
(Received via mailing list)
I'm running ruby 1.8.5-3 for Cygwin under Win XP Pro SP 2. Here's some
code:

require 'tempfile'

Dir.chdir("./aDir") do
   Tempfile.open("johndoe", ".") do |f|
      # Can be even empty
   end
end

With this code, the temporary file in ./aDir will not be removed. Is
this a bug, a Cygwin/Windows "feature", or what? How to get around
this thing?
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-03-21 14:01
(Received via mailing list)
On 21.03.2007 11:48, vulpes wrote:
>
> With this code, the temporary file in ./aDir will not be removed. Is
> this a bug, a Cygwin/Windows "feature", or what? How to get around
> this thing?

If you do this it will be removed (regardless whether you use chdir or
not) - at least that's the behavior I observe on my system:

Tempfile.open("johndoe", "/tmp") do |f|
    # Can be even empty
end

Basically the chdir isn't needed anyway.  It appears you hit a bug in
the stdlib: it seems to try to delete "./<tmpfilename>" but fails
because the file does not exist (remember that "." points to a different
directory then).

I just had a quick check of the Tempfile code and it appears that no
attempts are made to get an absolute path.  There is not a single
occurrence of expand_path in tempfile.rb.

The obvious workaround is to use an absolute path (see above).

Kind regards

  robert
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2007-03-21 16:40
(Received via mailing list)
On Mar 21, 6:57 am, Robert Klemme <shortcut...@googlemail.com> wrote:
> >    end
>     # Can be even empty
>
> The obvious workaround is to use an absolute path (see above).

Looks like a bug to me. Please file it on the RubyForge tracker (and
the patch, too, if you've got one).

Thanks,

Dan
17908c7c54cefa673d7cd2d6f2c3c8a5?d=identicon&s=25 vulpes (Guest)
on 2007-03-21 18:11
(Received via mailing list)
> Basically the chdir isn't needed anyway.  It appears you hit a bug in
> the stdlib: it seems to try to delete "./<tmpfilename>" but fails
> because the file does not exist (remember that "." points to a different
> directory then).

Point is that I encountered this while using RubyZip. If I'm trying to
edit a zip file in another directory with RubyZip, it is unable to
delete the temp file it creates. And there I have tried using absolute
paths, it doesn't work.
This topic is locked and can not be replied to.