comparison mercurial/util.py @ 705:574869103985

Merge with TAH manifest hash: 197e0d1a0d7376a9eb72381330462f06490ab821
author mpm@selenic.com
date Thu, 14 Jul 2005 22:56:55 -0800
parents 31a9aa890016 5ca319a641e1
children 1c0c413cccdd c6b912f8b5b2 8db4d406b3d3 d2422f10c136
comparison
equal deleted inserted replaced
694:51eb248d3348 705:574869103985
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:
44 os.rename(src, dst) 44 os.rename(src, dst)
45 except: 45 except:
46 os.unlink(dst) 46 os.unlink(dst)
47 os.rename(src, dst) 47 os.rename(src, dst)
48 48
49 def copytree(src, dst, copyfile):
50 """Copy a directory tree, files are copied using 'copyfile'."""
51 names = os.listdir(src)
52 os.mkdir(dst)
53
54 for name in names:
55 srcname = os.path.join(src, name)
56 dstname = os.path.join(dst, name)
57 if os.path.isdir(srcname):
58 copytree(srcname, dstname, copyfile)
59 elif os.path.isfile(srcname):
60 copyfile(srcname, dstname)
61 else:
62 raise IOError("Not a regular file: %r" % srcname)
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
49 # Platfor specific varients 72 # Platfor specific varients
50 if os.name == 'nt': 73 if os.name == 'nt':
51 nulldev = 'NUL:' 74 nulldev = 'NUL:'
52 75
53 def is_exec(f, last): 76 def is_exec(f, last):
57 pass 80 pass
58 81
59 def pconvert(path): 82 def pconvert(path):
60 return path.replace("\\", "/") 83 return path.replace("\\", "/")
61 84
62 def makelock(info, pathname): 85 makelock = _makelock_file
63 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) 86 readlock = _readlock_file
64 os.write(ld, info)
65 os.close(ld)
66
67 def readlock(pathname):
68 return file(pathname).read()
69 87
70 else: 88 else:
71 nulldev = '/dev/null' 89 nulldev = '/dev/null'
72 90
73 def is_exec(f, last): 91 def is_exec(f, last):
88 106
89 def pconvert(path): 107 def pconvert(path):
90 return path 108 return path
91 109
92 def makelock(info, pathname): 110 def makelock(info, pathname):
93 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)
94 118
95 def readlock(pathname): 119 def readlock(pathname):
96 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