mercurial/util.py
changeset 4828 41ad4105dde9
parent 4827 89defeae88f3
child 4832 0875082d5471
--- a/mercurial/util.py	Wed Jul 11 17:40:41 2007 -0300
+++ b/mercurial/util.py	Wed Jul 11 17:40:41 2007 -0300
@@ -1260,6 +1260,12 @@
         self.base = base
         self.audit = audit
 
+    def __getattr__(self, name):
+        if name == '_can_symlink':
+            self._can_symlink = checklink(self.base)
+            return self._can_symlink
+        raise AttributeError(name)
+
     def __call__(self, path, mode="r", text=False, atomictemp=False):
         if self.audit:
             audit_path(path)
@@ -1282,6 +1288,26 @@
                 rename(mktempcopy(f), f)
         return posixfile(f, mode)
 
+    def symlink(self, src, dst):
+        if self.audit:
+            audit_path(dst)
+        linkname = os.path.join(self.base, dst)
+        try:
+            os.unlink(linkname)
+        except OSError:
+            pass
+
+        dirname = os.path.dirname(linkname)
+        if not os.path.exists(dirname):
+            os.makedirs(dirname)
+
+        if self._can_symlink:
+            os.symlink(src, linkname)
+        else:
+            f = self(self, dst, "w")
+            f.write(src)
+            f.close()
+
 class chunkbuffer(object):
     """Allow arbitrary sized chunks of data to be efficiently read from an
     iterator over chunks of arbitrary size."""