HowTo get ruby to report a sumbolic link?

J

James Byrne

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?
 
B

Ben Bleything

Which tells me that the link is there but it is reporting the target
directory and not the link itself. =A0How do I tell if the thing that I a= m
checking is a symbolic link to a directory and not the directory itself?

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
 
J

James Byrne

Ben said:
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.
 
B

Ben Bleything

As File::stat automatically follows symbolic links, symlink? will always
be false for an object returned by File::stat.

You're right. Sorry, jumped the gun. There's also File.symlink?,
which does work correctly.

Ben
 
J

James Byrne

Ben said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,834
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top