Determining if a file_accessor still points to a valid file?

36 views
Skip to first unread message

Adrian Kwok

unread,
Mar 27, 2013, 5:20:25 PM3/27/13
to dragonf...@googlegroups.com
Hello,

This is kind of an odd question, but I wasn't able to find an answer after digging through the documentation.

How do I verify that a file_accessor is actually valid on the disk (i.e., the _uid still points to an existing file)?  Right now, if you try to access an attribute (say, .size) on a file_accessor that is no longer valid, Dragonfly raises an error.  While this probably won't happen often in practice, my application would still like to handle such cases gracefully.

Is there something like a file.exists? method?  Right now I have a hacky way of determining this but I don't like it:

def has_file?
  begin
    !file.nil? && file.size
  rescue
    false
  end
end

Thanks!

Adrian Kwok

unread,
May 13, 2013, 4:37:25 PM5/13/13
to dragonf...@googlegroups.com
Is there really no cleaner approach to this?  Ideally I'd like to write an analyser that just does a File.exist? on the object's path, but I can't even get to that step since Dragonfly's retrieve() throws the error before you can do anything.

Adrian
Reply all
Reply to author
Forward
0 new messages