guard/guard-process

Can't remove files

mattfordham opened this issue · 6 comments

I am attempting the following to clear a static html page cache whenever a file is saved. It doesn't work. Doesn't give any errors either.

guard 'process', :name => 'Clear Static Page Cache', :command => 'rm -rf public/static_page_caching/*' do
watch(%r{(public/).+.(css|js|html)})
end

Maybe it is a permissions issue? Any ideas? Thanks!

Actually, it looks like it is the global. The following worked:

guard 'process', :name => 'Clear Static Page Cache', :command => 'rm -rf public/static_page_caching/folder_name' do
watch(%r{(public/).+.(css|js|html)})
end

Any idea why the global doesn't work? Thanks!

Permissions really is the only thing that I can think of. Are the permissions (and owners) of the public/static_page_caching directory and its sub-directories different or identical? Do you get partial deletions with the global?

No, it wouldn't do partial deletions. Seems like it was the global that was messing things up. I switched to this, which works:

guard 'process', :name => 'Clear Static Page Cache', :command => 'find public/static_page_caching/. -type d -mindepth 1 -maxdepth 1 -exec rm -rf {} ;' do
watch(%r{(public/templates/).+.(css|js|html)})
end

That's really strange. To be honest I haven't used guard-process for these kind of tasks, I built it to run processes in the foreground that keep on running (like "rails s" or rails runners in infinite loops). When guard detects a change it then kills said process and restarts it. In cases like yours you don't want processes killed, you just want the command executed. When I have a bit of time I'll see if I can make an option to disable the process killing feature in the Guardfile per guard-process instance.

Out of curiosity were there a lot of files in those directories? Would the global rm command work manually where it failed with guard-process?

I hear ya. No worries, I'm happy with my solution.

Not too many files, no. And yes, when I use the same command as normal on the command line, it works.

Thanks!

guard-process v1.0.5 adds a dont_stop option, when set to true it won't kill the process when Guard does a reload (instead it will wait for the running process to finish, and then start a new one).