Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 704:5ca319a641e1
Make makelock and readlock work on filesystems without symlink support.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Make makelock and readlock work on filesystems without symlink support.
This way you can have a repository on a fat partiton, e.g. a USB stick.
manifest hash: cea2c120ef2b25a50c5d98b59648f773feefe470
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFC1t5yW7P1GVgWeRoRAsKjAJ9BFcn/EqBK/dmJ4BY1pPIZIbDDJACghN3p
VCQS6CJ72MHpzhOOsnOpHzE=
=laDT
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 14 Jul 2005 22:51:47 +0100 |
parents | df78d8ccac4c |
children | 574869103985 |
comparison
equal
deleted
inserted
replaced
703:fb6f85ecc863 | 704:5ca319a641e1 |
---|---|
3 # Copyright 2005 K. Thananchayan <thananck@yahoo.com> | 3 # Copyright 2005 K. Thananchayan <thananck@yahoo.com> |
4 # | 4 # |
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 = {} |
12 for f in g: | 12 for f in g: |
13 if f not in seen: | 13 if f not in seen: |
59 elif os.path.isfile(srcname): | 59 elif os.path.isfile(srcname): |
60 copyfile(srcname, dstname) | 60 copyfile(srcname, dstname) |
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:' |
67 | 75 |
68 def is_exec(f, last): | 76 def is_exec(f, last): |
72 pass | 80 pass |
73 | 81 |
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' |
87 | 90 |
88 def is_exec(f, last): | 91 def is_exec(f, last): |
103 | 106 |
104 def pconvert(path): | 107 def pconvert(path): |
105 return path | 108 return path |
106 | 109 |
107 def makelock(info, pathname): | 110 def makelock(info, pathname): |
108 os.symlink(info, pathname) | 111 try: |
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): |
111 return os.readlink(pathname) | 120 try: |
121 return os.readlink(pathname) | |
122 except OSError, why: | |
123 if why.errno == errno.EINVAL: | |
124 return _readlock_file(pathname) | |
125 else: | |
126 raise |