wafsamba/samba_utils.py: override symlink to allow force link
[metze/samba/wip.git] / buildtools / wafsamba / samba_utils.py
index 93ce317f114504ddced550e8ad99884f01e17e8a..ad97de1859ba24c4afd5106b4f9694b0dc855643 100644 (file)
@@ -1,6 +1,7 @@
 # a waf tool to add autoconf-like macros to the configure section
 # and for SAMBA_ macros for building libraries, binaries etc
 
+import errno
 import os, sys, re, fnmatch, shlex, inspect
 from optparse import SUPPRESS_HELP
 from waflib import Build, Options, Utils, Task, Logs, Configure, Errors, Context
@@ -289,6 +290,18 @@ def recursive_dirlist(dir, relbase, pattern=None):
     return ret
 
 
+def symlink(src, dst, force=True):
+    """Can create symlink by force"""
+    try:
+        os.symlink(src, dst)
+    except OSError as exc:
+        if exc.errno == errno.EEXIST and force:
+            os.remove(dst)
+            os.symlink(src, dst)
+        else:
+            raise
+
+
 def mkdir_p(dir):
     '''like mkdir -p'''
     if not dir: