]> code.ossystems Code Review - openembedded-core.git/commitdiff
rootfspostcommands: remove shadow backup files instead of trying to sort
authorPatrick Ohly <patrick.ohly@intel.com>
Fri, 10 Feb 2017 11:29:14 +0000 (12:29 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 19 Feb 2017 14:16:51 +0000 (06:16 -0800)
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@intel.com>
meta/lib/rootfspostcommands.py

index 6a9b8b47b7a4f4e2921669797bbe23f4e1c7d5cc..4742e0613ce5f147a0dee40ee2301d603dbb5735 100644 (file)
@@ -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)