Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory resource should remove files and replace with a directory #9175

Open
jimwise opened this issue Dec 18, 2019 · 2 comments
Open

Directory resource should remove files and replace with a directory #9175

jimwise opened this issue Dec 18, 2019 · 2 comments

Comments

@jimwise
Copy link

@jimwise jimwise commented Dec 18, 2019

Description

The directory resource only checks path existence and permissions, not that the resource target actually is a directory. Thus, the replication recipe below, which creates (1) a file and then (2) a directory at the same path succeeds and leaves a file behind, when it should (non-idempotently) end up with a directory at that path.

Chef Version

lindon$ chef-client --version
Chef Infra Client: 15.6.10
lindon$ 

Platform Version

lindon$ cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
lindon$ 

Replication Case

The following self-contained recipe demonstrates the bug:

file '/var/tmp/test-chef-bug' do
  mode '0755'
  owner 'root'
  group node['root_group']
  content 'test'
  action :create
end

directory '/var/tmp/test-chef-bug' do
  mode '0755'
  owner 'root'
  group node['root_group']
  action :create
end

Client Output

lindon$ sudo chef-client
Starting Chef Infra Client, version 15.6.10
[...]
Chef Infra Client finished, 8/475 resources updated in 13 seconds
lindon$ ls -l /var/tmp/test-chef-bug 
-rwxr-xr-x. 1 root root 4 Dec 17 20:02 /var/tmp/test-chef-bug
lindon$ 

Stacktrace

No stack trace -- chef-client run completes without error.

@skippyj

This comment has been minimized.

Copy link
Contributor

@skippyj skippyj commented Dec 22, 2019

If I'm reading this right, I think it was a pretty easy fix? My attached PR just adjusts the create/delete action blocks from evaluating unless File.exist? to unless File.directory?

@jimwise

This comment has been minimized.

Copy link
Author

@jimwise jimwise commented Dec 22, 2019

@lamont-granquist lamont-granquist changed the title Schrödinger's resource is both a file and a directory Directory resource should remove files and replace with a directory Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.