wic: Fix (again) partition files UIDs on multi rootfs images

Commit 450335ba5e73a375eb9932b4c4cf37979640dbfc copies the pseudo
database to the working directory in order to have ownership information
when the filesystem is generated.

Unfortunately this does not work anymore. The filenames on the database
are absolute and there is no information about the new directory.

Instead of fixing the database, we could redo a bit the way we patch the
fstab file. Now I am saving the old contents of fstab, modifying the
file and then reverting the changes on exit.

This is faster than the previous approach, although it can cause
indeterminism if the application is killed before finishing.

(From OE-Core rev: dcbf7b864dd1713b54a172d8714ce1508482f086)

Signed-off-by: Ricardo Ribalda Delgado <ricardo@ribalda.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ricardo Ribalda Delgado 2019-07-18 15:13:56 +02:00 committed by Richard Purdie
parent 050a96fe03
commit 58589bc538

View File

@ -49,7 +49,6 @@ class DirectPlugin(ImagerPlugin):
# parse possible 'rootfs=name' items # parse possible 'rootfs=name' items
self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' ')) self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' '))
self.replaced_rootfs_paths = {}
self.bootimg_dir = bootimg_dir self.bootimg_dir = bootimg_dir
self.kernel_dir = kernel_dir self.kernel_dir = kernel_dir
self.native_sysroot = native_sysroot self.native_sysroot = native_sysroot
@ -59,6 +58,7 @@ class DirectPlugin(ImagerPlugin):
self.compressor = options.compressor self.compressor = options.compressor
self.bmap = options.bmap self.bmap = options.bmap
self.no_fstab_update = options.no_fstab_update self.no_fstab_update = options.no_fstab_update
self.original_fstab = None
self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0],
strftime("%Y%m%d%H%M")) strftime("%Y%m%d%H%M"))
@ -104,24 +104,13 @@ class DirectPlugin(ImagerPlugin):
with open(fstab_path) as fstab: with open(fstab_path) as fstab:
fstab_lines = fstab.readlines() fstab_lines = fstab.readlines()
self.original_fstab = fstab_lines.copy()
if self._update_fstab(fstab_lines, self.parts): if self._update_fstab(fstab_lines, self.parts):
# copy rootfs dir to workdir to update fstab
# as rootfs can be used by other tasks and can't be modified
new_pseudo = os.path.realpath(os.path.join(self.workdir, "pseudo"))
from_dir = os.path.join(os.path.join(image_rootfs, ".."), "pseudo")
from_dir = os.path.realpath(from_dir)
copyhardlinktree(from_dir, new_pseudo)
new_rootfs = os.path.realpath(os.path.join(self.workdir, "rootfs_copy"))
copyhardlinktree(image_rootfs, new_rootfs)
fstab_path = os.path.join(new_rootfs, 'etc/fstab')
os.unlink(fstab_path)
with open(fstab_path, "w") as fstab: with open(fstab_path, "w") as fstab:
fstab.writelines(fstab_lines) fstab.writelines(fstab_lines)
else:
return new_rootfs self.original_fstab = None
def _update_fstab(self, fstab_lines, parts): def _update_fstab(self, fstab_lines, parts):
"""Assume partition order same as in wks""" """Assume partition order same as in wks"""
@ -170,14 +159,8 @@ class DirectPlugin(ImagerPlugin):
filesystems from the artifacts directly and combine them into filesystems from the artifacts directly and combine them into
a partitioned image. a partitioned image.
""" """
if self.no_fstab_update: if not self.no_fstab_update:
new_rootfs = None self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
else:
new_rootfs = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
if new_rootfs:
# rootfs was copied to update fstab
self.replaced_rootfs_paths[new_rootfs] = self.rootfs_dir['ROOTFS_DIR']
self.rootfs_dir['ROOTFS_DIR'] = new_rootfs
for part in self.parts: for part in self.parts:
# get rootfs size from bitbake variable if it's not set in .ks file # get rootfs size from bitbake variable if it's not set in .ks file
@ -253,8 +236,6 @@ class DirectPlugin(ImagerPlugin):
else: else:
suffix = '["%s"]:' % (part.mountpoint or part.label) suffix = '["%s"]:' % (part.mountpoint or part.label)
rootdir = part.rootfs_dir rootdir = part.rootfs_dir
if rootdir in self.replaced_rootfs_paths:
rootdir = self.replaced_rootfs_paths[rootdir]
msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), rootdir) msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), rootdir)
msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
@ -292,6 +273,12 @@ class DirectPlugin(ImagerPlugin):
if os.path.isfile(path): if os.path.isfile(path):
shutil.move(path, os.path.join(self.outdir, fname)) shutil.move(path, os.path.join(self.outdir, fname))
#Restore original fstab
if self.original_fstab:
fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab"
with open(fstab_path, "w") as fstab:
fstab.writelines(self.original_fstab)
# remove work directory # remove work directory
shutil.rmtree(self.workdir, ignore_errors=True) shutil.rmtree(self.workdir, ignore_errors=True)