From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mail.openembedded.org (Postfix) with ESMTP id 91CEF74578 for ; Fri, 20 Jul 2018 07:44:52 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jul 2018 00:44:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,378,1526367600"; d="scan'208";a="55819318" Received: from anmitta2-mobl1.png.intel.com ([10.221.21.63]) by fmsmga007.fm.intel.com with ESMTP; 20 Jul 2018 00:44:52 -0700 From: Anuj Mittal To: openembedded-core@lists.openembedded.org Date: Fri, 20 Jul 2018 15:44:50 +0800 Message-Id: <20180720074450.23555-1-anuj.mittal@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [PATCH] wic/engine: improve error reporting when using rm with wic X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2018 07:44:52 -0000 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 --- scripts/lib/wic/engine.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index f0c5ff0aaf..3f2eaa4ff8 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: -- 2.17.1