diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-09 15:09:16 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-09 15:09:18 +0200 |
commit | 98fe750774ac252fe35c42b752e68108b594e43f (patch) | |
tree | 849e9ad1f5e558d610a6d42711eb9f6b49e35e02 /utils.py | |
parent | 2635541daec35024390dc973ff16e7603c94ce39 (diff) | |
parent | 6d8dee0c92dc914a501e2e0fe3a5e044f5d6d872 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.9
Change-Id: I73f39966a2af7aa935e1890e29c9b71573aae97c
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -270,9 +270,28 @@ def copyfile(src, dst, force=True, vars=None): log.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst)) return - log.info("Copying file %s to %s." % (src, dst)) - - shutil.copy2(src, dst) + if not os.path.islink(src): + log.info("Copying file %s to %s." % (src, dst)) + shutil.copy2(src, dst) + else: + linkTargetPath = os.path.realpath(src) + if os.path.dirname(linkTargetPath) == os.path.dirname(src): + linkTarget = os.path.basename(linkTargetPath) + linkName = os.path.basename(src) + currentDirectory = os.getcwd() + try: + targetDir = dst if os.path.isdir(dst) else os.path.dirname(dst) + os.chdir(targetDir) + if os.path.exists(linkName): + os.remove(linkName) + log.info("Symlinking %s -> %s in %s." % (linkName, linkTarget, targetDir)) + os.symlink(linkTarget, linkName) + except OSError: + log.error("%s -> %s: Error creating symlink" % (linkName, linkTarget)) + finally: + os.chdir(currentDirectory) + else: + log.error("%s -> %s: Can only create symlinks within the same directory" % (src, linkTargetPath)) return dst |