diff options
Diffstat (limited to 'git')
-rw-r--r-- | git/test/test_config.py | 8 | ||||
-rw-r--r-- | git/util.py | 53 |
2 files changed, 32 insertions, 29 deletions
diff --git a/git/test/test_config.py b/git/test/test_config.py index b807413b..bd2bad0a 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -12,8 +12,7 @@ from git import ( GitConfigParser ) from git.compat import ( - string_types, - is_win,) + string_types) from git.config import cp from git.test.lib import ( TestCase, @@ -22,6 +21,7 @@ from git.test.lib import ( from git.test.lib import with_rw_directory import os.path as osp +from git.util import rmfile _tc_lock_fpaths = osp.join(osp.dirname(__file__), 'fixtures/*.lock') @@ -29,9 +29,7 @@ _tc_lock_fpaths = osp.join(osp.dirname(__file__), 'fixtures/*.lock') def _rm_lock_files(): for lfp in glob.glob(_tc_lock_fpaths): - if is_win and osp.isfile(lfp): - os.chmod(lfp, 0o777) - os.remove(lfp) + rmfile(lfp) class TestBase(TestCase): diff --git a/git/util.py b/git/util.py index f6f6dea9..87ef38d3 100644 --- a/git/util.py +++ b/git/util.py @@ -5,37 +5,39 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php from __future__ import unicode_literals +import getpass +import logging import os +import platform import re -import time -import stat import shutil -import platform -import getpass -import logging +import stat +import time -# NOTE: Some of the unused imports might be used/imported by others. -# Handle once test-cases are back up and running. -from .exc import InvalidGitRepositoryError +from git.compat import is_win +from gitdb.util import ( # NOQA + make_sha, + LockedFD, + file_contents_ro, + LazyMixin, + to_hex_sha, + to_bin_sha +) + +import os.path as osp from .compat import ( MAXSIZE, defenc, PY3 ) +from .exc import InvalidGitRepositoryError + +# NOTE: Some of the unused imports might be used/imported by others. +# Handle once test-cases are back up and running. # Most of these are unused here, but are for use by git-python modules so these # don't see gitdb all the time. Flake of course doesn't like it. -from gitdb.util import (# NOQA - make_sha, - LockedFD, - file_contents_ro, - LazyMixin, - to_hex_sha, - to_bin_sha -) -from git.compat import is_win - __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', @@ -72,6 +74,14 @@ def rmtree(path): return shutil.rmtree(path, False, onerror) +def rmfile(path): + """Ensure file deleted also on *Windows* where read-only files need special treatment.""" + if osp.isfile(path): + if is_win: + os.chmod(path, 0o777) + os.remove(path) + + def stream_copy(source, destination, chunk_size=512 * 1024): """Copy all data from the source stream into the destination stream in chunks of size chunk_size @@ -585,12 +595,7 @@ class LockFile(object): # instead of failing, to make it more usable. lfp = self._lock_file_path() try: - # on bloody windows, the file needs write permissions to be removable. - # Why ... - if is_win: - os.chmod(lfp, 0o777) - # END handle win32 - os.remove(lfp) + rmfile(lfp) except OSError: pass self._owns_lock = False |