{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/32016","repository_url":"https://api.github.com/repos/saltstack/salt","labels_url":"https://api.github.com/repos/saltstack/salt/issues/32016/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/32016/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/32016/events","html_url":"https://github.com/saltstack/salt/issues/32016","id":142313525,"number":32016,"title":"file creation inside a clean directory is not possible","user":{"login":"tampakrap","id":48949,"avatar_url":"https://avatars.githubusercontent.com/u/48949?v=3","gravatar_id":"","url":"https://api.github.com/users/tampakrap","html_url":"https://github.com/tampakrap","followers_url":"https://api.github.com/users/tampakrap/followers","following_url":"https://api.github.com/users/tampakrap/following{/other_user}","gists_url":"https://api.github.com/users/tampakrap/gists{/gist_id}","starred_url":"https://api.github.com/users/tampakrap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tampakrap/subscriptions","organizations_url":"https://api.github.com/users/tampakrap/orgs","repos_url":"https://api.github.com/users/tampakrap/repos","events_url":"https://api.github.com/users/tampakrap/events{/privacy}","received_events_url":"https://api.github.com/users/tampakrap/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/saltstack/salt/labels/Pending%20Discussion","name":"Pending Discussion","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/saltstack/salt/milestones/37","html_url":"https://github.com/saltstack/salt/milestones/Blocked","labels_url":"https://api.github.com/repos/saltstack/salt/milestones/37/labels","id":343741,"number":37,"title":"Blocked","description":"Issues which are blocked in some way, whether they need further discussion, clarification, justification, or are blocked for some other reason.","creator":{"login":"basepi","id":702318,"avatar_url":"https://avatars.githubusercontent.com/u/702318?v=3","gravatar_id":"","url":"https://api.github.com/users/basepi","html_url":"https://github.com/basepi","followers_url":"https://api.github.com/users/basepi/followers","following_url":"https://api.github.com/users/basepi/following{/other_user}","gists_url":"https://api.github.com/users/basepi/gists{/gist_id}","starred_url":"https://api.github.com/users/basepi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basepi/subscriptions","organizations_url":"https://api.github.com/users/basepi/orgs","repos_url":"https://api.github.com/users/basepi/repos","events_url":"https://api.github.com/users/basepi/events{/privacy}","received_events_url":"https://api.github.com/users/basepi/received_events","type":"User","site_admin":false},"open_issues":389,"closed_issues":776,"state":"open","created_at":"2013-05-28T22:24:12Z","updated_at":"2016-03-21T15:16:30Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-03-21T10:53:51Z","updated_at":"2016-03-21T15:29:25Z","closed_at":null,"body":"### Description of Issue/Question\r\n\r\nWhen defining a directory with `clean: True`, and also creating a file inside this directory, then salt cleans the directory and creates the file in every state.highstate run (sometimes even with wrong order, thus creating the file and then removing it).\r\n\r\nThe expected behaviour would be to remove all of the unmanaged files, and keep the managed ones (the ones created via salt).\r\n\r\n### Setup\r\n*Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).*\r\n\r\n```\r\nclean-directory:\r\n  file.directory:\r\n    - name: /tmp/directory\r\n    - clean: True\r\n\r\ncreate-file-inside-clean-dir:\r\n  file.managed:\r\n    - name: /tmp/directory/test\r\n```\r\n\r\n### Steps to Reproduce Issue\r\n*Include debug logs if possible and relevant.*\r\n\r\n(run multiple state.highstate)\r\n\r\n```\r\n----------\r\n          ID: clean-directory\r\n    Function: file.directory\r\n        Name: /tmp/directory\r\n      Result: True\r\n     Comment: Files cleaned from directory /tmp/directory\r\n     Started: 10:52:05.352310\r\n    Duration: 1.166 ms\r\n     Changes:   \r\n              ----------\r\n              removed:\r\n                  - /tmp/directory/test\r\n----------\r\n          ID: create-file-inside-clean-dir\r\n    Function: file.managed\r\n        Name: /tmp/directory/test\r\n      Result: True\r\n     Comment: Empty file\r\n     Started: 10:52:05.353880\r\n    Duration: 1.662 ms\r\n     Changes:   \r\n              ----------\r\n              new:\r\n                  file /tmp/directory/test created\r\n```\r\n\r\n### Versions Report\r\n*Provided by running* ``salt --versions-report``\r\n\r\n```\r\nSalt Version:\r\n           Salt: 2015.8.7\r\n \r\nDependency Versions:\r\n         Jinja2: 2.8\r\n       M2Crypto: Not Installed\r\n           Mako: Not Installed\r\n         PyYAML: 3.11\r\n          PyZMQ: 14.7.0\r\n         Python: 2.7.9 (default, Dec 21 2014, 11:02:59) [GCC]\r\n           RAET: Not Installed\r\n        Tornado: 4.3\r\n            ZMQ: 4.1.3\r\n           cffi: 0.8.2\r\n       cherrypy: Not Installed\r\n       dateutil: Not Installed\r\n          gitdb: Not Installed\r\n      gitpython: Not Installed\r\n          ioflo: Not Installed\r\n        libgit2: Not Installed\r\n        libnacl: Not Installed\r\n   msgpack-pure: Not Installed\r\n msgpack-python: 0.4.6\r\n   mysql-python: Not Installed\r\n      pycparser: 2.10\r\n       pycrypto: 2.6.1\r\n         pygit2: Not Installed\r\n   python-gnupg: Not Installed\r\n          smmap: Not Installed\r\n        timelib: Not Installed\r\n \r\nSystem Versions:\r\n           dist: SuSE 12 x86_64\r\n        machine: x86_64\r\n        release: 3.12.51-52.39-default\r\n         system: SUSE Linux Enterprise Server  12 x86_64\r\n```"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/199340331","html_url":"https://github.com/saltstack/salt/issues/32016#issuecomment-199340331","issue_url":"https://api.github.com/repos/saltstack/salt/issues/32016","id":199340331,"user":{"login":"jfindlay","id":702905,"avatar_url":"https://avatars.githubusercontent.com/u/702905?v=3","gravatar_id":"","url":"https://api.github.com/users/jfindlay","html_url":"https://github.com/jfindlay","followers_url":"https://api.github.com/users/jfindlay/followers","following_url":"https://api.github.com/users/jfindlay/following{/other_user}","gists_url":"https://api.github.com/users/jfindlay/gists{/gist_id}","starred_url":"https://api.github.com/users/jfindlay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfindlay/subscriptions","organizations_url":"https://api.github.com/users/jfindlay/orgs","repos_url":"https://api.github.com/users/jfindlay/repos","events_url":"https://api.github.com/users/jfindlay/events{/privacy}","received_events_url":"https://api.github.com/users/jfindlay/received_events","type":"User","site_admin":false},"created_at":"2016-03-21T15:29:25Z","updated_at":"2016-03-21T15:29:25Z","body":"@tampakrap, thanks for reporting.  To prevent order-dependent states from running out of order, you can use a requisite to predicate one state upon the other:\r\n```sls\r\nclean-directory:\r\n  file.directory:\r\n    - name: /tmp/directory\r\n    - clean: True\r\n\r\ncreate-file-inside-clean-dir:\r\n  file.managed:\r\n    - name: /tmp/directory/test\r\n    - requires:\r\n        file: clean-directory\r\n```\r\nIt seems that in order achieve what you are wanting to do you will have to use some more involved logic than a simple `clean_directory: True`.  You might try using a git repo, or maintaining a state that checks for patterns that match and remove all files in the directory that should not be there."}}