mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add some debug messages
This commit is contained in:
parent
de409e68d4
commit
f6ea2e49fd
2 changed files with 24 additions and 28 deletions
|
@ -15,6 +15,7 @@ import os.path
|
|||
import stat
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import salt.utils.files
|
||||
import salt.utils.path
|
||||
|
@ -1345,41 +1346,37 @@ def remove(path, force=False):
|
|||
# Symlinks. The shutil.rmtree function will remove the contents of
|
||||
# the Symlink source in windows.
|
||||
|
||||
path = os.path.expanduser(path)
|
||||
path = Path(os.path.expanduser(path))
|
||||
|
||||
if not os.path.isabs(path):
|
||||
raise SaltInvocationError(f"File path must be absolute: {path}")
|
||||
if not path.is_absolute():
|
||||
raise SaltInvocationError(f"File path must be absolute: {str(path)}")
|
||||
|
||||
# Does the file/folder exists
|
||||
if not os.path.exists(path) and not is_link(path):
|
||||
raise CommandExecutionError(f"Path not found: {path}")
|
||||
if not path.exists() and not path.is_symlink():
|
||||
raise CommandExecutionError(f"Path not found: {str(path)}")
|
||||
|
||||
# Remove ReadOnly Attribute
|
||||
file_attributes = win32api.GetFileAttributes(str(path))
|
||||
if force:
|
||||
# Get current file attributes
|
||||
file_attributes = win32api.GetFileAttributes(path)
|
||||
win32api.SetFileAttributes(path, win32con.FILE_ATTRIBUTE_NORMAL)
|
||||
win32api.SetFileAttributes(str(path), win32con.FILE_ATTRIBUTE_NORMAL)
|
||||
|
||||
try:
|
||||
if os.path.isfile(path):
|
||||
if path.is_file() or path.is_symlink():
|
||||
# A file and a symlinked file are removed the same way
|
||||
os.remove(path)
|
||||
elif is_link(path):
|
||||
# If it's a symlink directory, use the rmdir command
|
||||
os.rmdir(path)
|
||||
path.unlink()
|
||||
else:
|
||||
for name in os.listdir(path):
|
||||
item = f"{path}\\{name}"
|
||||
# If its a normal directory, recurse to remove it's contents
|
||||
remove(item, force)
|
||||
for child in path.iterdir():
|
||||
# If it's a normal directory, recurse to remove its contents
|
||||
remove(str(child), force)
|
||||
|
||||
# rmdir will work now because the directory is empty
|
||||
os.rmdir(path)
|
||||
path.rmdir()
|
||||
except OSError as exc:
|
||||
if force:
|
||||
# Reset attributes to the original if delete fails.
|
||||
win32api.SetFileAttributes(path, file_attributes)
|
||||
raise CommandExecutionError(f"Could not remove '{path}': {exc}")
|
||||
win32api.SetFileAttributes(str(path), file_attributes)
|
||||
raise CommandExecutionError(f"Could not remove '{str(path)}': {exc}")
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -17,13 +17,7 @@ def chocolatey(modules):
|
|||
|
||||
@pytest.fixture()
|
||||
def clean(chocolatey):
|
||||
try:
|
||||
# If chocolatey is not installed, this will throw an error
|
||||
chocolatey.chocolatey_version(refresh=True)
|
||||
# If we get this far, chocolatey is installed... let's uninstall
|
||||
chocolatey.unbootstrap()
|
||||
except CommandExecutionError:
|
||||
pass
|
||||
result = chocolatey.unbootstrap()
|
||||
|
||||
# Try to get the new version, should throw an error
|
||||
try:
|
||||
|
@ -34,7 +28,9 @@ def clean(chocolatey):
|
|||
# Assert the chocolatey is not installed
|
||||
assert chocolatey_version is None
|
||||
try:
|
||||
yield
|
||||
# We're yielding "result" here so we can see any problems with
|
||||
# unbootstrap if the test fails
|
||||
yield result
|
||||
finally:
|
||||
try:
|
||||
# If chocolatey is not installed, this will throw an error
|
||||
|
@ -46,7 +42,10 @@ def clean(chocolatey):
|
|||
|
||||
|
||||
def test_bootstrap(chocolatey, clean):
|
||||
chocolatey.bootstrap()
|
||||
# We're defining "result" here to see the output of the bootstrap function
|
||||
# if the test fails
|
||||
result = chocolatey.bootstrap()
|
||||
# Let's run it outside the try/except to see what the error is
|
||||
try:
|
||||
chocolatey_version = chocolatey.chocolatey_version(refresh=True)
|
||||
except CommandExecutionError:
|
||||
|
|
Loading…
Add table
Reference in a new issue