# HG changeset patch # User mpm@selenic.com # Date 1119411820 28800 # Node ID 10c43444a38e824b254e3d82a1789deb2a50cd01 # Parent 43b8da7420a90e4ddc5184f7c2b5aaa7776f6fe5 [PATCH] Enables lock work under the other 'OS' -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PATCH] Enables lock work under the other 'OS' From: K Thananchayan os.symlink is not supported under Windows. This patch introduces util.mklockf, util.getlowner that use regular files under Winodws but symlink under unix. tweaked by mpm: - changed function names - fixed to work on UNIX manifest hash: 6f650a78a3b203dcad2f861582500b6b4036599a -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuN5sywK+sNU5EO8RAva8AJ9L9z/JHRAJS1bix48ZzSpn9ZUyPwCffhmg UfLSFBmd5tPDDi3mgsrdDEA= =ZYS9 -----END PGP SIGNATURE----- diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -6,6 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. import os, time +import util class LockHeld(Exception): pass @@ -34,10 +35,10 @@ class lock: def trylock(self): pid = os.getpid() try: - os.symlink(str(pid), self.f) + util.makelock(str(pid), self.f) self.held = 1 except: - raise LockHeld(os.readlink(self.f)) + raise LockHeld(util.readlock(self.f)) def release(self): if self.held: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -18,7 +18,22 @@ def rename(src, dst): if os.name == 'nt': def pconvert(path): return path.replace("\\", "/") + + def makelock(info, pathname): + ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) + os.write(ld, info) + os.close(ld) + + def readlock(pathname): + return file(pathname).read() else: def pconvert(path): return path + def makelock(info, pathname): + os.symlink(info, pathname) + + def readlock(pathname): + return os.readlink(pathname) + +