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

Back-port #49244 to 2018.3.3 #49361

Merged
merged 4 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions salt/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ def _onerror(func, path, exc_info):
if os.path.islink(path) or not os.path.isdir(path):
os.remove(path)
else:
if salt.utils.platform.is_windows():
try:
path = salt.utils.stringutils.to_unicode(path)
except TypeError:
pass
shutil.rmtree(path, onerror=_onerror)


Expand Down
9 changes: 7 additions & 2 deletions tests/unit/fileserver/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

TMP_SOCK_DIR = tempfile.mkdtemp(dir=TMP)
TMP_REPO_DIR = os.path.join(TMP, 'gitfs_root')
if salt.utils.platform.is_windows():
TMP_REPO_DIR = TMP_REPO_DIR.replace('\\', '/')
INTEGRATION_BASE_FILES = os.path.join(FILES, 'file', 'base')
UNICODE_FILENAME = 'питон.txt'
UNICODE_DIRNAME = UNICODE_ENVNAME = 'соль'
Expand Down Expand Up @@ -422,6 +424,9 @@ def setUpClass(cls):

# Add a tag
repo.create_tag(TAG_NAME, 'HEAD')
# Older GitPython versions do not have a close method.
if hasattr(repo, 'close'):
repo.close()
finally:
if orig_username is not None:
os.environ[username_key] = orig_username
Expand All @@ -436,7 +441,7 @@ def tearDownClass(cls):
'''
for path in (cls.tmp_cachedir, cls.tmp_sock_dir, TMP_REPO_DIR):
try:
shutil.rmtree(path, onerror=_rmtree_error)
salt.utils.files.rm_rf(path)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
Expand All @@ -457,7 +462,7 @@ def setUp(self):
_clear_instance_map()
for subdir in ('gitfs', 'file_lists'):
try:
shutil.rmtree(os.path.join(self.tmp_cachedir, subdir))
salt.utils.files.rm_rf(os.path.join(self.tmp_cachedir, subdir))
except OSError as exc:
if exc.errno != errno.ENOENT:
raise
Expand Down