Check if directory is empty


#1

I have Ubuntu 16.04 with chef-client 14.1.1.
I have two steps with contrary conditions but both are run (spoiler: that folder is empty)

docker_container "build_packages" do
....
  only_if { ::Dir.empty?('/opt/chef/deb/') }
end

bash 'publish new deb package' do
....  
  not_if { ::Dir.empty?('/opt/chef/deb/') }
end

Why is it happening?


#2

you can do like this

not_if { Dir["/opt/chef/deb/*"].empty? }

#3

It doesn’t work as well.
I made a test. I removed bash block and there was nothing in /opt/chef/deb/ folder after first step. So there is nothing at folder and not_if isn’t catching it.