Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the directory is symlink in chef

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

directory "/var/www/html/" do
  action :delete
  only_if ???
end
like image 725
morizotter Avatar asked Apr 06 '14 09:04

morizotter


2 Answers

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
like image 168
sethvargo Avatar answered Nov 10 '22 18:11

sethvargo


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.

like image 1
Josh Jolly Avatar answered Nov 10 '22 17:11

Josh Jolly