Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > tempfile.rb and unlink on windows

Reply
Thread Tools

tempfile.rb and unlink on windows

 
 
Nicholas Manning
Guest
Posts: n/a
 
      05-19-2009
PROBLEM

Was setting up a rails projects on a windows machine for and the project
required RubyInline. When running rake db:migrate for the first time
RubyInline creates a temp file to ensure it can have access to something
like /tmp/ruby_inline but causes an error:

rake aborted!
File exists - /tmp/ruby_inline3712-0

The problem here is that on windows, doing something like (in order to
emulate this problem)

ruby -r tempfile -e 'Tempfile.new("foo").unlink'

Will *not* work on Windows (XP Pro).

COMMENTS

Whoever freakin wrote Tempfile#unlink had this little gem in the code:
rescue Errno::EACCES
# may not be able to unlink on Windows; just ignore
So if it can't delete (unlink) the file it just silently fails - not
cool.

SOLUTION

After reading this post:
http://blade.nagaokaut.ac.jp/cgi-bin...ruby-core/2848 I
applied the following patch and it worked finally (thanks to Florian
Frank who wrote it).

--- lib/tempfile.rb 23 Jul 2003 16:37:35 -0000 1.19
+++ lib/tempfile.rb 5 May 2004 23:33:57 -0000
@@ -106,7 +106,10 @@ class Tempfile < SimpleDelegator
# file.
def unlink
# keep this order for thread safeness
- File.unlink(@tmpname) if File.exist?(@tmpname)
+ if File.exist?(@tmpname)
+ closed? or close
+ File.unlink(@tmpname)
+ end
@@cleanlist.delete(@tmpname) if @@cleanlist
end
alias delete unlink


Can anyone provide any insight on this?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      05-19-2009
> -----Original Message-----
> From: [private.php?do=newpm&u=]
> Sent: Tuesday, May 19, 2009 9:02 AM
> To: ruby-talk ML
> Subject: tempfile.rb and unlink on windows
>
> PROBLEM
>
> Was setting up a rails projects on a windows machine for and the
> project
> required RubyInline. When running rake db:migrate for the first time
> RubyInline creates a temp file to ensure it can have access to
> something
> like /tmp/ruby_inline but causes an error:
>
> rake aborted!
> File exists - /tmp/ruby_inline3712-0
>
> The problem here is that on windows, doing something like (in order to
> emulate this problem)
>
> ruby -r tempfile -e 'Tempfile.new("foo").unlink'
>
> Will *not* work on Windows (XP Pro).
>
> COMMENTS
>
> Whoever freakin wrote Tempfile#unlink had this little gem in the code:
> rescue Errno::EACCES
> # may not be able to unlink on Windows; just ignore
> So if it can't delete (unlink) the file it just silently fails - not
> cool.
>
> SOLUTION
>
> After reading this post:
> http://blade.nagaokaut.ac.jp/cgi-bin...ruby-core/2848 I
> applied the following patch and it worked finally (thanks to Florian
> Frank who wrote it).
>
> --- lib/tempfile.rb 23 Jul 2003 16:37:35 -0000 1.19
> +++ lib/tempfile.rb 5 May 2004 23:33:57 -0000
> @@ -106,7 +106,10 @@ class Tempfile < SimpleDelegator
> # file.
> def unlink
> # keep this order for thread safeness
> - File.unlink(@tmpname) if File.exist?(@tmpname)
> + if File.exist?(@tmpname)
> + closed? or close
> + File.unlink(@tmpname)
> + end
> @@cleanlist.delete(@tmpname) if @@cleanlist
> end
> alias delete unlink
>
>
> Can anyone provide any insight on this?


Your patch looks good to me. I would submit it on their redmine site:

http://redmine.ruby-lang.org

Regards,

Dan


 
Reply With Quote
 
 
 
 
Nicholas Manning
Guest
Posts: n/a
 
      05-19-2009
Daniel Berger wrote:
>> required RubyInline. When running rake db:migrate for the first time
>> ruby -r tempfile -e 'Tempfile.new("foo").unlink'
>>
>> # file.
>>
>>
>> Can anyone provide any insight on this?

>
> Your patch looks good to me. I would submit it on their redmine site:
>
> http://redmine.ruby-lang.org
>
> Regards,
>
> Dan


Yeah I will get around to it but it's just f*cked up that the rescue
clause just silently fails and says in a comment "oh may fail on windows
but who cares" lol
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: os.unlink on Windows Thomas Jollans Python 5 08-09-2010 08:08 AM
How can I unlink/delete an open file in Windows? Coffee Pot C Programming 12 10-19-2008 11:04 PM
File.unlink(nonwestern_filename) ---> Error on Windows johan556@gmail.com Ruby 4 07-06-2007 03:55 PM
os.unlink() AND win32api.DeleteFile() rbt Python 4 01-24-2006 01:17 PM
can't get unlink to work on windows jan_buys@hotmail.com Perl Misc 12 12-29-2004 08:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57