tags:

views:

34

answers:

1

I'm experiencing a weird situation with deleting files in Ruby, the code seems to report correctly, but the physical file isn't removed from my hard drive. I can do rm path/to/file on the command line - that works. I can even open up the Rails console and File.safe_unlink the file and that also works, it's just within my Rails app it fails to delete the actual file:

def destroy
  Rails.logger.debug local_path #=> /Users/ryan/.../public/system/.../file.jpg
  Rails.logger.debug File.exist?(local_path) #=> true
  File.safe_unlink(local_path)
  Rails.logger.debug File.exist?(local_path) #=> false
  # yet the physical file actually STILL exists!
end

The physical file is within a Git repo (the repo is stored within /public/system/) any gotchas with that? I've tried using the ruby-git gem to delete the file using the rm command it provides, but that doesn't delete the file either.

I've opened up all the permissions on the files during testing and still nothing works. I've also confirmed this with File.writable?(local_path) which returned true.

Any thoughts why it could be preventing the file from being removed?

Cheers.

+1  A: 

Have you checked the permissions on the directory? Deletion is a directory write operation, not file write operation. (rm will also check file perms and ask if you really want to do it, as a courtesy, if the file is write-protected; but if the directory isn't writable, it flat out refuses.)

Amadan
Okay, I think I just face-palmed myself. I never knew it was a directory-level permission, thanks!
Ryan Townsend