This option lets the install-files config extension overwrite existing files.
A file will only be overwritten if the overwrite flag is specified for that file.
Since the overwrite arg is optionally prepended to the manifest line,
this patch should not break existing manifests
---
morphlib/exts/install-files.configure | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/morphlib/exts/install-files.configure
b/morphlib/exts/install-files.configure
index 669fc51..f70137c 100755
--- a/morphlib/exts/install-files.configure
+++ b/morphlib/exts/install-files.configure
@@ -37,7 +37,7 @@ class InstallFilesConfigureExtension(cliapp.Application):
The manifest is formatted as:
- <octal mode> <uid decimal> <gid decimal> <filename>
+ [<overwrite?>] <octal mode> <uid decimal> <gid decimal>
<filename>
Where the filename is how the file is found inside whatever directory
the manifest is stored in, and also the path within the system to
@@ -65,14 +65,15 @@ class InstallFilesConfigureExtension(cliapp.Application):
self.install_entry(entry, manifest_dir, target_root)
def install_entry(self, entry, manifest_root, target_root):
- entry_data = re.split('\W+', entry.strip(), maxsplit=3)
- mode = int(entry_data[0], 8)
- uid = int(entry_data[1])
- gid = int(entry_data[2])
- path = entry_data[3]
+ overwrite = entry.split(' ')[0] == 'overwrite'
+ entry_data = re.split('\W+', entry.strip(), maxsplit=overwrite + 3)
+ mode = int(entry_data[overwrite + 0], 8)
+ uid = int(entry_data[overwrite + 1])
+ gid = int(entry_data[overwrite + 2])
+ path = entry_data[overwrite + 3]
dest_path = os.path.join(target_root, './' + path)
if stat.S_ISDIR(mode):
- if os.path.exists(dest_path):
+ if os.path.exists(dest_path) and not overwrite:
dest_stat = os.stat(dest_path)
if (mode != dest_stat.st_mode
or uid != dest_stat.st_uid
@@ -86,7 +87,7 @@ class InstallFilesConfigureExtension(cliapp.Application):
os.chmod(dest_path, mode)
elif stat.S_ISLNK(mode):
- if os.path.lexists(dest_path):
+ if os.path.lexists(dest_path) and not overwrite:
raise cliapp.AppException('Symlink already exists at %s'
% dest_path)
else:
@@ -96,7 +97,7 @@ class InstallFilesConfigureExtension(cliapp.Application):
os.lchown(dest_path, uid, gid)
elif stat.S_ISREG(mode):
- if os.path.lexists(dest_path):
+ if os.path.lexists(dest_path) and not overwrite:
raise cliapp.AppException('File already exists at %s'
% dest_path)
else:
--
1.7.10.4