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

Commita803803

Browse files
committed
Lockfile now uses low-level commands to interact with the filesystem in order to make it impossible for threads to overwrite each other if we are talking about miliseconds. This renders plenty of 'special' handling redundant
1 parent0bb2fc8 commita803803

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

‎lib/git/utils.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ def _lock_file_path(self):
119119
"""
120120
return"%s.lock"% (self._file_path)
121121

122-
def_get_id(self):
123-
"""Returns string id to be written into the lock file"""
124-
return"%i|%i"% (os.getpid(),hash(self))
125-
126122
def_has_lock(self):
127123
"""
128124
Return
@@ -134,17 +130,6 @@ def _has_lock(self):
134130
ifnotself._owns_lock:
135131
returnFalse
136132

137-
lock_file=self._lock_file_path()
138-
try:
139-
fp=open(lock_file,"rb")
140-
pid=fp.read()
141-
fp.close()
142-
exceptIOError:
143-
raiseAssertionError("The lock file at %s could not be read"%lock_file)
144-
145-
ifpid!=self._get_id():
146-
raiseAssertionError("We claim to own the lock at %s, but it was not owned by our process %r, but by %r"% (lock_file,self._get_id(),pid ))
147-
148133
returnTrue
149134

150135
def_obtain_lock_or_raise(self):
@@ -160,21 +145,11 @@ def _obtain_lock_or_raise(self):
160145
ifos.path.isfile(lock_file):
161146
raiseIOError("Lock for file %r did already exist, delete %r in case the lock is illegal"% (self._file_path,lock_file))
162147

163-
my_id=self._get_id()
164-
fp=open(lock_file,"wb")
165-
fp.write(my_id)
166-
fp.close()
167-
168-
# verify its truly us who got the lock - if two threads are doing this within the
169-
# fraction of a millisecond, it is possible to actually trick the FS
170-
# and two threads write, but only one succeeds.
171-
fp=open(lock_file,'rb')
172-
actual_id=fp.read()
173-
fp.close()
174-
ifactual_id!=my_id:
175-
msg="Failed to obtain lock for file %r as the process identified by %r outraced this process or thread %r"% (self._file_path,actual_id,my_id)
176-
raiseIOError(msg)
177-
# END verification
148+
try:
149+
fd=os.open(lock_file,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0)
150+
os.close(fd)
151+
exceptOSError,e:
152+
raiseIOError(str(e))
178153

179154
self._owns_lock=True
180155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp