8

I just want to do delete directory if it is not symlnik.

directory "/var/www/html/" do
  action :delete
  only_if ???
end
morizotter
  • 1,926
  • 2
  • 24
  • 34

2 Answers2

14

The selected answer will not work on Windows or systems where Bash is the default interpreter. You should use a Ruby solution to be cross-platform (and faster, since there's no process spawning):

directory '/var/www/html' do
  action :delete
  not_if { File.symlink?('/var/www/html') }
end
sethvargo
  • 26,739
  • 10
  • 86
  • 156
  • 1
    Thank you! It sounds good. I changed the recipe and it works nice! Cookbook needs to be cross-platform. I changed the answer selection to yours. – morizotter Apr 07 '14 at 16:35
1

How about:

directory "/var/www/html/" do
    action :delete
    not_if "test -L /var/www/html/"
end

test -L $file returns 0 (true) if $file is a symlink.

Josh Jolly
  • 11,258
  • 2
  • 39
  • 55