From: James Byrne on 22 Jul 2010 16:08 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/.
From: Ben Bleything on 22 Jul 2010 16:16 On Thu, Jul 22, 2010 at 1:08 PM, James Byrne <byrnejb(a)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? 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
From: James Byrne on 22 Jul 2010 17:26 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/.
From: Ben Bleything on 22 Jul 2010 17:56 On Thu, Jul 22, 2010 at 2:26 PM, James Byrne <byrnejb(a)harte-lyne.ca> wrote: > 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
From: James Byrne on 22 Jul 2010 18:34 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/.
|
Pages: 1 Prev: Typical Ruby (non-rails) project structure. Next: Emacs Ruby mode bug |