##// END OF EJS Templates
Make makelock and readlock work on filesystems without symlink support....
Thomas Arendsen Hein -
r704:5ca319a6 default
parent child Browse files
Show More
@@ -37,7 +37,7 b' class lock:'
37 try:
37 try:
38 util.makelock(str(pid), self.f)
38 util.makelock(str(pid), self.f)
39 self.held = 1
39 self.held = 1
40 except:
40 except (OSError, IOError):
41 raise LockHeld(util.readlock(self.f))
41 raise LockHeld(util.readlock(self.f))
42
42
43 def release(self):
43 def release(self):
@@ -5,7 +5,7 b''
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 import os
8 import os, errno
9
9
10 def unique(g):
10 def unique(g):
11 seen = {}
11 seen = {}
@@ -61,6 +61,14 b' def copytree(src, dst, copyfile):'
61 else:
61 else:
62 raise IOError("Not a regular file: %r" % srcname)
62 raise IOError("Not a regular file: %r" % srcname)
63
63
64 def _makelock_file(info, pathname):
65 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)
66 os.write(ld, info)
67 os.close(ld)
68
69 def _readlock_file(pathname):
70 return file(pathname).read()
71
64 # Platfor specific varients
72 # Platfor specific varients
65 if os.name == 'nt':
73 if os.name == 'nt':
66 nulldev = 'NUL:'
74 nulldev = 'NUL:'
@@ -74,13 +82,8 b" if os.name == 'nt':"
74 def pconvert(path):
82 def pconvert(path):
75 return path.replace("\\", "/")
83 return path.replace("\\", "/")
76
84
77 def makelock(info, pathname):
85 makelock = _makelock_file
78 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)
86 readlock = _readlock_file
79 os.write(ld, info)
80 os.close(ld)
81
82 def readlock(pathname):
83 return file(pathname).read()
84
87
85 else:
88 else:
86 nulldev = '/dev/null'
89 nulldev = '/dev/null'
@@ -105,7 +108,19 b' else:'
105 return path
108 return path
106
109
107 def makelock(info, pathname):
110 def makelock(info, pathname):
111 try:
108 os.symlink(info, pathname)
112 os.symlink(info, pathname)
113 except OSError, why:
114 if why.errno == errno.EEXIST:
115 raise
116 else:
117 _makelock_file(info, pathname)
109
118
110 def readlock(pathname):
119 def readlock(pathname):
120 try:
111 return os.readlink(pathname)
121 return os.readlink(pathname)
122 except OSError, why:
123 if why.errno == errno.EINVAL:
124 return _readlock_file(pathname)
125 else:
126 raise
General Comments 0
You need to be logged in to leave comments. Login now