[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] Re: [PATCH] python-virtinst: add error handling to VirtualDisk._clone_local()



Patch attached now.

On Sat, Nov 21, 2009 at 02:43:43PM +0100, Guido Günther wrote:
> Hi,
> attached patch fixes:
> 
> http://bugs.debian.org/555748
> 
> src_fd is not defined because the os.open() already fails (i.e. due to
> missing permissions). Attached patch (against 0.500.0 but applies
> against current hg) catches OSError and propagates the error to the
> upper levels. Please apply.
> Cheers,
>  -- Guido
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx sigxcpu org>
Date: Sat, 21 Nov 2009 14:06:41 +0100
Subject: [PATCH] Add error handling to VirtualDisk._clone_local

Closes: #555748
---
 virtinst/VirtualDisk.py |   46 +++++++++++++++++++++++++---------------------
 1 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
index 67e2d03..781b11e 100644
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -859,29 +859,33 @@ class VirtualDisk(VirtualDevice):
 
         zeros = '\0' * 4096
 
+        src_fd, dst_fd = None, None
         try:
-            src_fd = os.open(self.clone_path, os.O_RDONLY)
-            dst_fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
-
-            i=0
-            while 1:
-                l = os.read(src_fd, clone_block_size)
-                s = len(l)
-                if s == 0:
-                    meter.end(size_bytes)
-                    break
-                # check sequence of zeros
-                if sparse and zeros == l:
-                    os.lseek(dst_fd, s, 1)
-                else:
-                    b = os.write(dst_fd, l)
-                    if s != b:
-                        meter.end(i)
+            try:
+                src_fd = os.open(self.clone_path, os.O_RDONLY)
+                dst_fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
+
+                i=0
+                while 1:
+                    l = os.read(src_fd, clone_block_size)
+                    s = len(l)
+                    if s == 0:
+                        meter.end(size_bytes)
                         break
-                i += s
-                if i < size_bytes:
-                    meter.update(i)
-
+                    # check sequence of zeros
+                    if sparse and zeros == l:
+                        os.lseek(dst_fd, s, 1)
+                    else:
+                        b = os.write(dst_fd, l)
+                        if s != b:
+                            meter.end(i)
+                            break
+                    i += s
+                    if i < size_bytes:
+                        meter.update(i)
+            except OSError, e:
+                raise RuntimeError(_("Error cloning diskimage %s to %s: %s") %
+                                       (self.clone_path, self.path, str(e)))
         finally:
             if src_fd is not None:
                 os.close(src_fd)
-- 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]