Commit d6f45b1f authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Daniel P. Berrange

image: ignore OSError on listdir()

If the directory to list is missing, don't raise an exception but
return empty list instead. This fixes for example running
"virt-sandbox-image list" without a
~/.local/share/libvirt/templates/virt-builder.
Signed-off-by: 's avatarMarc-André Lureau <marcandre.lureau@redhat.com>
parent ad14f860
......@@ -358,7 +358,11 @@ class DockerSource(base.Source):
def list_templates(self, templatedir):
indexes = []
imagedirs = os.listdir(templatedir)
try:
imagedirs = os.listdir(templatedir)
except OSError:
return []
for imagetagid in imagedirs:
indexfile = templatedir + "/" + imagetagid + "/index.json"
if os.path.exists(indexfile):
......@@ -552,7 +556,11 @@ class DockerSource(base.Source):
def _get_image_list(self, image, templatedir):
imageparent = {}
imagenames = {}
imagedirs = os.listdir(templatedir)
imagedirs = []
try:
imagedirs = os.listdir(templatedir)
except OSError:
pass
for imagetagid in imagedirs:
indexfile = templatedir + "/" + imagetagid + "/index.json"
if os.path.exists(indexfile):
......@@ -585,7 +593,11 @@ class DockerSource(base.Source):
imageusage = {}
imageparent = {}
imagenames = {}
imagedirs = os.listdir(templatedir)
imagedirs = []
try:
imagedirs = os.listdir(templatedir)
except OSError:
pass
for imagetagid in imagedirs:
indexfile = templatedir + "/" + imagetagid + "/index.json"
if os.path.exists(indexfile):
......
......@@ -68,7 +68,11 @@ class VirtBuilderSource(base.Source):
def list_templates(self, templatedir):
files = []
imagefiles = os.listdir(templatedir)
try:
imagefiles = os.listdir(templatedir)
except OSError:
return []
for filename in imagefiles:
if not filename.endswith(".qcow2"):
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment