diff options
author | Javier Jardón <jjardon@gnome.org> | 2015-04-29 22:52:43 +0100 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-04-30 17:15:46 +0000 |
commit | 93b034f045a2c7443122d7b082ad4460339907d0 (patch) | |
tree | 9606ce1ec808fc1b31b7177be05aea19bb280f94 /morphlib/exts | |
parent | 7e5bab59aa4c292e93654892e656d807891084ba (diff) | |
download | morph-93b034f045a2c7443122d7b082ad4460339907d0.tar.gz |
install-files.configure: make possible to overwrite symlinks
os.symlink will fail if the origin file/link already exist
Change-Id: I8175c8dce699e55c3e39e35dfd45c0c19b8bd96d
Diffstat (limited to 'morphlib/exts')
-rwxr-xr-x | morphlib/exts/install-files.configure | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/morphlib/exts/install-files.configure b/morphlib/exts/install-files.configure index c2970243..341cce61 100755 --- a/morphlib/exts/install-files.configure +++ b/morphlib/exts/install-files.configure @@ -24,6 +24,7 @@ to install into the target system. import cliapp import os +import errno import re import sys import shlex @@ -53,6 +54,14 @@ class InstallFilesConfigureExtension(cliapp.Application): for entry in entries: self.install_entry(entry, manifest_dir, target_root) + def force_symlink(self, source, link_name): + try: + os.symlink(source, link_name) + except OSError as e: + if e.errno == errno.EEXIST: + os.remove(link_name) + os.symlink(source, link_name) + def install_entry(self, entry, manifest_root, target_root): m = re.match('(template )?(overwrite )?' '([0-7]+) ([0-9]+) ([0-9]+) (\S+)', entry) @@ -91,7 +100,7 @@ class InstallFilesConfigureExtension(cliapp.Application): else: linkdest = os.readlink(os.path.join(manifest_root, './' + path)) - os.symlink(linkdest, dest_path) + self.force_symlink(linkdest, dest_path) os.lchown(dest_path, uid, gid) elif stat.S_ISREG(mode): |