From a405383e63c35d7b56108f192ca74755b122a639 Mon Sep 17 00:00:00 2001 From: Anuj Mittal Date: Fri, 20 Jul 2018 15:44:50 +0800 Subject: 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. Signed-off-by: Anuj Mittal Signed-off-by: Ross Burton --- scripts/lib/wic/engine.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index 11dedb8cac..850cec30e5 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py @@ -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: -- cgit 1.2.3-korg