##// END OF EJS Templates
lock: factor code to read lock into a separate function...
Siddharth Agarwal -
r26290:9664d32b default
parent child Browse files
Show More
@@ -100,6 +100,19 b' class lock(object):'
100 raise error.LockUnavailable(why.errno, why.strerror,
100 raise error.LockUnavailable(why.errno, why.strerror,
101 why.filename, self.desc)
101 why.filename, self.desc)
102
102
103 def _readlock(self):
104 """read lock and return its value
105
106 Returns None if no lock exists, pid for old-style locks, and host:pid
107 for new-style locks.
108 """
109 try:
110 return self.vfs.readlock(self.f)
111 except (OSError, IOError) as why:
112 if why.errno == errno.ENOENT:
113 return None
114 raise
115
103 def testlock(self):
116 def testlock(self):
104 """return id of locker if lock is valid, else None.
117 """return id of locker if lock is valid, else None.
105
118
@@ -111,12 +124,9 b' class lock(object):'
111 The lock file is only deleted when None is returned.
124 The lock file is only deleted when None is returned.
112
125
113 """
126 """
114 try:
127 locker = self._readlock()
115 locker = self.vfs.readlock(self.f)
128 if locker is None:
116 except (OSError, IOError) as why:
129 return None
117 if why.errno == errno.ENOENT:
118 return None
119 raise
120 try:
130 try:
121 host, pid = locker.split(":", 1)
131 host, pid = locker.split(":", 1)
122 except ValueError:
132 except ValueError:
General Comments 0
You need to be logged in to leave comments. Login now