Don't check the token if -t is not defined
[snf-image-creator] / image_creator / disk.py
index 4209462..a51611e 100644 (file)
@@ -45,6 +45,7 @@ import uuid
 import re
 import sys
 import guestfs
+import shutil
 from sendfile import sendfile
 
 
@@ -77,7 +78,7 @@ class Disk(object):
         self.tmp = tempfile.mkdtemp(prefix='.snf_image_creator.',
                                     dir=self._get_tmp_dir(tmp))
 
-        self._add_cleanup(os.removedirs, self.tmp)
+        self._add_cleanup(shutil.rmtree, self.tmp)
 
     def _get_tmp_dir(self, default=None):
         if default is not None:
@@ -209,7 +210,7 @@ class DiskDevice(object):
         self.size = 0
 
         self.g = guestfs.GuestFS()
-        self.g.add_drive_opts(self.real_device, readonly=0)
+        self.g.add_drive_opts(self.real_device, readonly=0, format="raw")
 
         # Before version 1.17.14 the recovery process, which is a fork of the
         # original process that called libguestfs, did not close its inherited
@@ -480,8 +481,15 @@ class DiskDevice(object):
                 progressbar.next()
                 while left > 0:
                     length = min(left, blocksize)
-                    _, sent = sendfile(dst.fileno(), src.fileno(), offset,
-                                       length)
+                    sent = sendfile(dst.fileno(), src.fileno(), offset, length)
+
+                    # Workaround for python-sendfile API change. In
+                    # python-sendfile 1.2.x (py-sendfile) the returning value
+                    # of sendfile is a tuple, where in version 2.x (pysendfile)
+                    # it is just a sigle integer.
+                    if isinstance(sent, tuple):
+                        sent = sent[1]
+
                     offset += sent
                     left -= sent
                     progressbar.goto((size - left) // MB)