From: nobu.nokada@... Date: 2005-05-15T09:22:30+09:00 Subject: Re: [ ruby-Bugs-1917 ] Pathname#unlink fails on a symlink which points to a directory. Hi, At Sun, 15 May 2005 06:40:08 +0900, noreply@rubyforge.org wrote in [ruby-core:04992]: > Initial Comment: > When you try to unlink a link to a directory Pathname#unlink fails like that: > > irb(main):001:0> Pathname.new('/tmp/bar').unlink > Errno::ENOTDIR: Not a directory - /tmp/bar > > I simply propose: > > # File pathname.rb, line 860 > def unlink() > if FileTest.directory? @path and not FileTest.symlink? @path > Dir.unlink @path > else > File.unlink @path > end > end The result of File.lstat can do it at a time. Index: pathname.rb =================================================================== RCS file: /cvs/ruby/src/ruby/lib/pathname.rb,v retrieving revision 1.38 diff -U2 -p -r1.38 pathname.rb --- pathname.rb 12 Dec 2004 16:02:08 -0000 1.38 +++ pathname.rb 15 May 2005 00:18:02 -0000 @@ -869,5 +869,5 @@ class Pathname # * mixed * # Dir.unlink as necessary. def unlink() - if FileTest.directory? @path + if File.lstat(@path).directory? Dir.unlink @path else -- Nobu Nakada