I am creating a series of symbolic links to target directories. I wish
to check to see if the symbolic link exists or not. When I do this
(using rspec):
File.stat(@soft_link_target).ftype.should == 'link'
I get this:
expected: "link",
got: "directory" (using ==)
Which tells me that the link is there but it is reporting the target
directory and not the link itself. How do I tell if the thing that I am
checking is a symbolic link to a directory and not the directory itself?
···
--
Posted via http://www.ruby-forum.com/.
ri File::Stat tells me that there's a #symlink? method you could use:
File.stat( @soft_link_target ).should be_symlink
... I believe that's the right syntax for rspec, but you get the idea.
Ben
···
On Thu, Jul 22, 2010 at 1:08 PM, James Byrne <byrnejb@harte-lyne.ca> wrote:
Which tells me that the link is there but it is reporting the target
directory and not the link itself. How do I tell if the thing that I am
checking is a symbolic link to a directory and not the directory itself?
Ben Bleything wrote:
ri File::Stat tells me that there's a #symlink? method you could use:
File.stat( @soft_link_target ).should be_symlink
... I believe that's the right syntax for rspec, but you get the idea.
rdoc also says:
As File::stat automatically follows symbolic links, symlink? will always
be false for an object returned by File::stat.
···
--
Posted via http://www.ruby-forum.com/\.
You're right. Sorry, jumped the gun. There's also File.symlink?,
which does work correctly.
Ben
···
On Thu, Jul 22, 2010 at 2:26 PM, James Byrne <byrnejb@harte-lyne.ca> wrote:
As File::stat automatically follows symbolic links, symlink? will always
be false for an object returned by File::stat.
Ben Bleything wrote:
You're right. Sorry, jumped the gun. There's also File.symlink?,
which does work correctly.
Yes, it does. Which surprises me since that is what I started with. I
suppose something else must have been wrong in the test and I simply
misdiagnosed the reason.
Thanks.
···
--
Posted via http://www.ruby-forum.com/\.