Skip to content

Commit 700d677

Browse files
bertdawg76dwoz
authored andcommitted
wrong changes message fixed
1 parent 83b2a03 commit 700d677

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

changelog/68052.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this fixes when a file is managed, and the same file is cleaned, an incorrect message is displayed saying "removed: Removed due to clean" when the file isn't actually removed

salt/states/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ def _check_directory(
10401040

10411041
def _check_changes(fname):
10421042
path = os.path.join(root, fname)
1043-
if path in keep:
1043+
if any(path in s for s in keep):
10441044
return {}
10451045
else:
10461046
if not salt.utils.stringutils.check_include_exclude(

tests/pytests/functional/states/file/test_directory.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import salt.utils.files
66
import salt.utils.path
77
import salt.utils.platform
8+
import salt.utils.win_dacl
89
import salt.utils.win_functions
910

1011
pytestmark = [
@@ -290,6 +291,65 @@ def test_directory_clean_require_in(modules, tmp_path, state_tree):
290291
assert wrong_file.exists() is False
291292

292293

294+
def test_directory_clean_require_in_good_message(modules, tmp_path, state_tree):
295+
"""
296+
file.directory test with clean=True and require_in file,
297+
the comment cannot be "removed": "Removed due to clean"
298+
"""
299+
name = tmp_path / "b-directory"
300+
name.mkdir()
301+
if IS_WINDOWS:
302+
principal = salt.utils.win_functions.get_current_user()
303+
salt.utils.win_dacl.set_owner(obj_name=str(name), principal=principal)
304+
dir = name / "one"
305+
dir.mkdir()
306+
good_file = dir / "good-file"
307+
good_file.write_text("good")
308+
309+
assert good_file.exists()
310+
assert good_file.is_file()
311+
312+
assert name.exists()
313+
assert name.is_dir()
314+
315+
assert dir.exists()
316+
assert dir.is_dir()
317+
318+
sls_contents = """
319+
some_dir:
320+
file.directory:
321+
- name: {name}
322+
- clean: true
323+
{good_file}:
324+
file.managed:
325+
- require_in:
326+
- file: some_dir
327+
""".format(
328+
name=name, good_file=good_file
329+
)
330+
331+
with pytest.helpers.temp_file("clean-require-in.sls", sls_contents, state_tree):
332+
ret = modules.state.sls("clean-require-in")
333+
expected_file = (
334+
f"File {good_file} exists with proper permissions. No changes made."
335+
)
336+
for state_run in ret:
337+
print("changes", state_run.changes)
338+
if IS_WINDOWS:
339+
if state_run.changes:
340+
expected_dir = f"Directory {name} updated"
341+
else:
342+
expected_dir = f"Directory {name} is in the correct state"
343+
else:
344+
expected_dir = f"The directory {name} is in the correct state"
345+
assert dir.exists()
346+
assert good_file.exists()
347+
assert good_file.read_text() == "good"
348+
assert (
349+
state_run.comment == expected_file or state_run.comment == expected_dir
350+
)
351+
352+
293353
def test_directory_clean_require_in_with_id(modules, tmp_path, state_tree):
294354
"""
295355
file.directory test with clean=True and require_in file with an ID

0 commit comments

Comments
 (0)