[elbe-devel] [PATCH v3] efilesystem: Fix copy_filelist copying none existing file

Olivier Dion dion at linutronix.de
Thu Aug 20 16:21:44 CEST 2020


Some files that are passed to copy_filelist() might not exist on the
source file system.  One such example is
'/etc/sysctl.d/99-sysctl.conf -> ../sysctl.conf'.

Thus, if the target of a symlink doesn't exists, create the link but
do not call copy_filelist() recursively with the target.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/efilesystem.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index ef697c46..18b592a4 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -56,6 +56,10 @@ def copy_filelist(src, file_lst, dst):
 
             tgt = src.readlink(f)
 
+            if not src.lexists(tgt):
+                dst.symlink(tgt, f, allow_exists=True)
+                continue
+
             # If the target is not yet in the destination RFS, we need
             # to defer the copy of the symlink after the target is
             # resolved.  Thus, we recusively call copy_filelist
@@ -78,8 +82,12 @@ def copy_filelist(src, file_lst, dst):
             dst.chown(f, st.st_uid, st.st_gid)
 
         else:
-            system('cp -a --reflink=auto "%s" "%s"' % (src.realpath(f),
-                                                       dst.realpath(f)))
+            try:
+                system('cp -a --reflink=auto "%s" "%s"' % (src.realpath(f),
+                                                           dst.realpath(f)))
+            except CommandError as E:
+                logging.warning("Error while copying from %s to %s of file %s - %s",
+                                src.path, dst.path, f, E)
 
     # update utime which will change after a file has been copied into
     # the directory
-- 
2.28.0



More information about the elbe-devel mailing list