[OE-core] [PATCH] rootfspostcommands: remove shadow backup files instead of trying to sort

Patrick Ohly patrick.ohly at intel.com
Fri Feb 10 12:04:38 UTC 2017


Backup are files sometimes are inconsistent and then cannot be
sorted (YOCTO #11043), and more importantly, are not needed in
the initial rootfs, so they get deleted.

Fixes: [YOCTO #11007]

Signed-off-by: Patrick Ohly <patrick.ohly at intel.com>
---
 meta/lib/rootfspostcommands.py | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/meta/lib/rootfspostcommands.py b/meta/lib/rootfspostcommands.py
index 6a9b8b4..4742e06 100644
--- a/meta/lib/rootfspostcommands.py
+++ b/meta/lib/rootfspostcommands.py
@@ -29,16 +29,28 @@ def sort_file(filename, mapping):
         f.write(b''.join(lines))
     return new_mapping
 
+def remove_backup(filename):
+    """
+    Removes the backup file for files like /etc/passwd.
+    """
+    backup_filename = filename + '-'
+    if os.path.exists(backup_filename):
+        os.unlink(backup_filename)
+
 def sort_passwd(sysconfdir):
     """
     Sorts passwd and group files in a rootfs /etc directory by ID.
+    Backup files are sometimes are inconsistent and then cannot be
+    sorted (YOCTO #11043), and more importantly, are not needed in
+    the initial rootfs, so they get deleted.
     """
-    for suffix in '', '-':
-        for main, shadow in (('passwd', 'shadow'),
-                             ('group', 'gshadow')):
-            filename = os.path.join(sysconfdir, main + suffix)
+    for main, shadow in (('passwd', 'shadow'),
+                         ('group', 'gshadow')):
+        filename = os.path.join(sysconfdir, main)
+        remove_backup(filename)
+        if os.path.exists(filename):
+            mapping = sort_file(filename, None)
+            filename = os.path.join(sysconfdir, shadow)
+            remove_backup(filename)
             if os.path.exists(filename):
-                mapping = sort_file(filename, None)
-                filename = os.path.join(sysconfdir, shadow + suffix)
-                if os.path.exists(filename):
-                    sort_file(filename, mapping)
+                 sort_file(filename, mapping)

base-commit: 652f7245ac95fd11c72f4ad62e0b99234a7e59c5
-- 
git-series 0.9.1



More information about the Openembedded-core mailing list