wic/engine: improve error reporting when using rm with wic

When trying to delete something from an ext partition using debugfs, we
don't show any error to the user when that operation fails.

Change this behavior to show the error generated by debugfs. Also,
fallback to use rmdir in case we are trying to delete a directory. However,
unlike mdeltree that is used for a FAT partition, there's no easy way to
delete a non empty directory. Show an error instead when that happens so
user can take appropriate action.

(From OE-Core rev: a405383e63c35d7b56108f192ca74755b122a639)

Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Anuj Mittal
2018-07-20 15:44:50 +08:00
committed by Richard Purdie
parent 866e437f21
commit b7b203d8ea

View File

@@ -340,9 +340,21 @@ class Disk:
"""Remove files/dirs from the partition."""
partimg = self._get_part_image(pnum)
if self.partitions[pnum].fstype.startswith('ext'):
exec_cmd("{} {} -wR 'rm {}'".format(self.debugfs,
cmd = "{} {} -wR 'rm {}'".format(self.debugfs,
self._get_part_image(pnum),
path), as_shell=True)
path)
out = exec_cmd(cmd , as_shell=True)
for line in out.splitlines():
if line.startswith("rm:"):
if "file is a directory" in line:
# Try rmdir to see if this is an empty directory. This won't delete
# any non empty directory so let user know about any error that this might
# generate.
print(exec_cmd("{} {} -wR 'rmdir {}'".format(self.debugfs,
self._get_part_image(pnum),
path), as_shell=True))
else:
raise WicError("Could not complete operation: wic %s" % str(line))
else: # fat
cmd = "{} -i {} ::{}".format(self.mdel, partimg, path)
try: