|
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
6 | 6 | from __future__ import unicode_literals |
7 | 7 |
|
| 8 | +import getpass |
| 9 | +import logging |
8 | 10 | import os |
| 11 | +import platform |
9 | 12 | import re |
10 | | -import time |
11 | | -import stat |
12 | 13 | import shutil |
13 | | -import platform |
14 | | -import getpass |
15 | | -import logging |
| 14 | +import stat |
| 15 | +import time |
16 | 16 |
|
17 | | -# NOTE: Some of the unused imports might be used/imported by others. |
18 | | -# Handle once test-cases are back up and running. |
19 | | -from .exc import InvalidGitRepositoryError |
| 17 | +from git.compat import is_win |
| 18 | +from gitdb.util import ( # NOQA |
| 19 | + make_sha, |
| 20 | + LockedFD, |
| 21 | + file_contents_ro, |
| 22 | + LazyMixin, |
| 23 | + to_hex_sha, |
| 24 | + to_bin_sha |
| 25 | +) |
| 26 | + |
| 27 | +import os.path as osp |
20 | 28 |
|
21 | 29 | from .compat import ( |
22 | 30 | MAXSIZE, |
23 | 31 | defenc, |
24 | 32 | PY3 |
25 | 33 | ) |
| 34 | +from .exc import InvalidGitRepositoryError |
| 35 | + |
26 | 36 |
|
| 37 | +# NOTE: Some of the unused imports might be used/imported by others. |
| 38 | +# Handle once test-cases are back up and running. |
27 | 39 | # Most of these are unused here, but are for use by git-python modules so these |
28 | 40 | # don't see gitdb all the time. Flake of course doesn't like it. |
29 | | -from gitdb.util import (# NOQA |
30 | | - make_sha, |
31 | | - LockedFD, |
32 | | - file_contents_ro, |
33 | | - LazyMixin, |
34 | | - to_hex_sha, |
35 | | - to_bin_sha |
36 | | -) |
37 | | -from git.compat import is_win |
38 | | - |
39 | 41 | __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", |
40 | 42 | "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", |
41 | 43 | "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', |
@@ -72,6 +74,14 @@ def onerror(func, path, exc_info): |
72 | 74 | return shutil.rmtree(path, False, onerror) |
73 | 75 |
|
74 | 76 |
|
| 77 | +def rmfile(path): |
| 78 | + """Ensure file deleted also on *Windows* where read-only files need special treatment.""" |
| 79 | + if osp.isfile(path): |
| 80 | + if is_win: |
| 81 | + os.chmod(path, 0o777) |
| 82 | + os.remove(path) |
| 83 | + |
| 84 | + |
75 | 85 | def stream_copy(source, destination, chunk_size=512 * 1024): |
76 | 86 | """Copy all data from the source stream into the destination stream in chunks |
77 | 87 | of size chunk_size |
@@ -585,12 +595,7 @@ def _release_lock(self): |
585 | 595 | # instead of failing, to make it more usable. |
586 | 596 | lfp = self._lock_file_path() |
587 | 597 | try: |
588 | | - # on bloody windows, the file needs write permissions to be removable. |
589 | | - # Why ... |
590 | | - if is_win: |
591 | | - os.chmod(lfp, 0o777) |
592 | | - # END handle win32 |
593 | | - os.remove(lfp) |
| 598 | + rmfile(lfp) |
594 | 599 | except OSError: |
595 | 600 | pass |
596 | 601 | self._owns_lock = False |
|
0 commit comments