I need to delete an application (MyApp.app), which has read only permissions in all its enclosed folders. Before I delete it, I should change the permissions on all enclosed files/directories to 0644. How do I do this recursively?
I've tried
begin; FileUtils.chmod(0644, '#{config.appPath}'); rescue; end
begin; FileUtils.rm_r('#{config.appPath}'); rescue; end
but FileUtils.chmod
doesn't work recursively. I cannot use Unix commands - it has to be Ruby.
EDIT: I cannot use Unix commands in the current context. OK, this is a RubyCocoa application and the source you see is a part of ruby script, that is supposed to uninstall the application (please don't comment on that, since that's the code my customer has). Uninstalling includes removing all traces of the application, killing the process and in the end deleting the application itself. Normally it works, but not in the case when for some reason the MyApp.app folder gets read only permission. So i thought to run a chmod recursively on the folder and them remove it, but it's not straight forward in Ruby for some reason. That's why i'm asking for a help. There are plenty examples on how to do it from a command line, but how do you do it from the code?
Here some more from the code, just to show how's it implemented:
code =<<FOO
require 'fileutils'
# kill the app before deleting files in case it writes files on exit
%x{/bin/kill -9 #{NSProcessInfo.processInfo.processIdentifier}}
begin; FileUtils.chmod(0644, '#{TBConfig.appPath}'); rescue; end
begin; FileUtils.rm_r('#{TBConfig.appPath}'); rescue; end
FOO
ff = Tempfile.new('timebridge')
ff.write(code)
ff.close
%x{/usr/bin/ruby #{ff.path}}
Thanks again.