Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 4/8] wic: isoimage-isohybrid: check result of glob()
Date: Fri, 14 Jul 2017 15:33:03 +0300	[thread overview]
Message-ID: <a44d31b81ec998481e11c175196bbb117fe25764.1500035131.git.ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <cover.1500035131.git.ed.bartosh@linux.intel.com>

isoimage-isohybrid plugin uses result of glob call to
get path to initrd image. When glob returns empty list
the plugin crashes with IndexError.

Checking if result of glob call is not empty should fix
the breakage.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 scripts/lib/wic/plugins/source/isoimage-isohybrid.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index ffa5429..ece4b0c 100644
--- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -164,9 +164,12 @@ class IsoImagePlugin(SourcePlugin):
 
             machine = os.path.basename(initrd_dir)
 
-            initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, machine, image_type))[0]
+            pattern = '%s/%s*%s.%s' % (initrd_dir, image_name, machine, image_type)
+            files = glob.glob(pattern)
+            if files:
+                initrd = files[0]
 
-        if not os.path.exists(initrd):
+        if not initrd or not os.path.exists(initrd):
             # Create initrd from rootfs directory
             initrd = "%s/initrd.cpio.gz" % cr_workdir
             initrd_dir = "%s/INITRD" % cr_workdir
-- 
2.1.4



  parent reply	other threads:[~2017-07-14 12:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 12:32 [PATCH v2 0/8] #11552 - wic: avoid unnecessary dependencies Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 1/8] wic: get rid of using wic-tools Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 2/8] wic: isoimage: do not remove temp directory Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 3/8] wic: build wic-tools only if wic is run manually Ed Bartosh
2017-07-14 12:33 ` Ed Bartosh [this message]
2017-07-14 12:33 ` [PATCH v2 5/8] wic-tools: don't create wic-tools.env Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 6/8] image_types_wic: set default WKS_FILE_DEPENDS Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 7/8] wic: isoimage-isohybrid: use grub-efi from deploy dir Ed Bartosh
2017-07-14 12:33 ` [PATCH v2 8/8] selftest: fixed 5 wic test cases Ed Bartosh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a44d31b81ec998481e11c175196bbb117fe25764.1500035131.git.ed.bartosh@linux.intel.com \
    --to=ed.bartosh@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox