0

I recently asked a question asking about how to test whether a directory/file exists in Ruby and I was redirected to this great post that has a lot of wonderful answers. Directory/File test existence answer.

The thing is though, I don't understand why my method doesn't work for testing to see if a directory exists. Here is what I have:

task :make_tmp_writable do
  on roles(:slave) do
    if test ?d "#{current_path}/tmp"
      execute "chmod g+w #{File.join(current_path,'tmp')}"
    else
     execute "mkdir #{current_path}/tmp"
     execute "chmod g+w #{File.join(current_path,'tmp')}"
    end
  end
end

This test always passes true every time and I don't understand why. On my linux system, the current_path/tmp file is not physically present on the system at all, yet this test always returns true. Why is it always returning true? This also seems to be the case with methods such as

FileTest.exist?(...)
Directory.exist?(....)

Can someone please explain to me why this keeps happening?

-----------EDIT----------------

I've tried experimenting with this method and the Directory/File/Kernel methods do work but not in the way that I'd like.

For example if you run these methods with keywords such as /var , /tmp, /bin, /sbin, etc. you will receive a true. My current_path is equal to /var/local/app/current. If I were to append a /var at the end, it will be false, but tmp returns true regardless. This indicates that there must be a duplicate tmp in my file system but it simply isn't there. Are there any other leads I can follow?

Community
  • 1
  • 1
Dan Rubio
  • 4,709
  • 10
  • 49
  • 106
  • Maybe `current_path` is `nil` or `""`. In that case `"#{current_path}/tmp"` would be `"/tmp"`. – Stefan Sep 11 '14 at 13:58
  • Thanks for the response @Stefan, I wish that was the case, but I've checked in pry and current_path evaluates to /var/local/app/current. I can only guess that there is a duplicate somewhere although I'm pretty sure there isn't. – Dan Rubio Sep 11 '14 at 14:18
  • I'm not sure why you aren't getting ```test': wrong number of arguments (1 for 2) (ArgumentError)``` you're missing a comma ```test ?d "/tmp"``` => ```test ?d, "/tmp"``` – jtzero Sep 12 '14 at 02:44

0 Answers0