Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab7a872

Browse files
committed
Updated file locking for Windows platform
1 parentd437f88 commitab7a872

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

‎git/util.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
from __future__importunicode_literals
77

8-
fromfcntlimportflock,LOCK_UN,LOCK_EX,LOCK_NB
98
importgetpass
109
importlogging
1110
importos
@@ -49,6 +48,57 @@
4948

5049
#{ Utility Methods
5150

51+
ifplatform.system()=='Windows':
52+
# This code is a derivative work of Portalocker http://code.activestate.com/recipes/65203/
53+
importwin32con
54+
importwin32file
55+
importpywintypes
56+
57+
LOCK_EX=win32con.LOCKFILE_EXCLUSIVE_LOCK
58+
LOCK_SH=0# the default
59+
LOCK_NB=win32con.LOCKFILE_FAIL_IMMEDIATELY
60+
LOCK_UN=1<<2
61+
62+
__overlapped=pywintypes.OVERLAPPED()
63+
64+
defflock(fd,flags=0):
65+
hfile=win32file._get_osfhandle(fd)
66+
67+
ifflags&LOCK_UN!=0:
68+
# Unlock file descriptor
69+
try:
70+
win32file.UnlockFileEx(hfile,0,-0x10000,__overlapped)
71+
exceptpywintypes.error,exc_value:
72+
# error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
73+
# To match the 'posix' implementation, silently ignore this error
74+
ifexc_value[0]==158:
75+
pass
76+
else:
77+
# Q: Are there exceptions/codes we should be dealing with here?
78+
raise
79+
80+
elifflags&LOCK_EX!=0:
81+
# Lock file
82+
try:
83+
win32file.LockFileEx(hfile,flags,0,-0x10000,__overlapped)
84+
exceptpywintypes.error,exc_value:
85+
ifexc_value[0]==33:
86+
# error: (33, 'LockFileEx',
87+
# 'The process cannot access the file because another process has locked
88+
# a portion of the file.')
89+
raiseIOError(33,exc_value[2])
90+
else:
91+
# Q: Are there exceptions/codes we should be dealing with here?
92+
raise
93+
94+
else:
95+
raiseNotImplementedError("Unsupported set of bitflags {}".format(bin(flags)))
96+
97+
98+
else:
99+
# from fcntl import flock, LOCK_UN, LOCK_EX, LOCK_NB
100+
pass
101+
52102

53103
defunbare_repo(func):
54104
"""Methods with this decorator raise InvalidGitRepositoryError if they
@@ -620,6 +670,7 @@ def _release_lock(self):
620670
rmfile(lock_file)
621671
exceptOSError:
622672
pass
673+
623674
self._owns_lock=False
624675
self._file_descriptor=None
625676

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp