[Pkg-libvirt-commits] [libvirt-sandbox] 35/42: image: ignore OSError on listdir()
Guido Guenther
agx at moszumanska.debian.org
Sat May 27 16:27:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
agx pushed a commit to branch debian/experimental
in repository libvirt-sandbox.
commit d6f45b1f36979b3e7e4ac2e386d6fd56e113ebf6
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date: Thu Aug 4 17:01:37 2016 +0400
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: Marc-André Lureau <marcandre.lureau at redhat.com>
---
libvirt-sandbox/image/sources/docker.py | 18 +++++++++++++++---
libvirt-sandbox/image/sources/virtbuilder.py | 6 +++++-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/libvirt-sandbox/image/sources/docker.py b/libvirt-sandbox/image/sources/docker.py
old mode 100644
new mode 100755
index f6724af..43e9c32
--- a/libvirt-sandbox/image/sources/docker.py
+++ b/libvirt-sandbox/image/sources/docker.py
@@ -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):
diff --git a/libvirt-sandbox/image/sources/virtbuilder.py b/libvirt-sandbox/image/sources/virtbuilder.py
old mode 100644
new mode 100755
index fefe0dd..6bd9695
--- a/libvirt-sandbox/image/sources/virtbuilder.py
+++ b/libvirt-sandbox/image/sources/virtbuilder.py
@@ -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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libvirt-sandbox.git
More information about the Pkg-libvirt-commits
mailing list