From 93b034f045a2c7443122d7b082ad4460339907d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Wed, 29 Apr 2015 22:52:43 +0100 Subject: install-files.configure: make possible to overwrite symlinks os.symlink will fail if the origin file/link already exist Change-Id: I8175c8dce699e55c3e39e35dfd45c0c19b8bd96d --- morphlib/exts/install-files.configure | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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): -- cgit v1.2.1