Revision 5b801534 image_creator/disk.py

b/image_creator/disk.py
120 120
        os.close(cowfd)
121 121
        self._add_cleanup(os.unlink, cow)
122 122
        # Create 1G cow sparse file
123
        dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', \
124
                                        'seek=%d' % (1024 * 1024))
123
        dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', 'seek=%d' % (1024 * 1024))
125 124
        cowdev = self._losetup(cow)
126 125

  
127 126
        snapshot = uuid.uuid4().hex
......
273 272

  
274 273
        if self.parttype == 'msdos' and last_partition['part_num'] > 4:
275 274
            raise FatalError("This disk contains logical partitions. "
276
                "Only primary partitions are supported.")
275
                                    "Only primary partitions are supported.")
277 276

  
278 277
        part_dev = "%s%d" % (self.guestfs_device, last_partition['part_num'])
279 278
        fs_type = self.g.vfs_type(part_dev)
......
299 298
        self.g.part_add(self.guestfs_device, 'p', start, end)
300 299

  
301 300
        self.size = (end + 1) * sector_size
302
        success("new image size is %dMB" %
303
                            ((self.size + 2 ** 20 - 1) // 2 ** 20))
301
        success("new size is %dMB" % ((self.size + 2 ** 20 - 1) // 2 ** 20))
304 302

  
305 303
        if self.parttype == 'gpt':
306 304
            ptable = GPTPartitionTable(self.real_device)
......
318 316
        progress_size = (self.size + 2 ** 20 - 1) // 2 ** 20  # in MB
319 317
        progressbar = progress("Dumping image file: ", 'mb')
320 318
        progressbar.max = progress_size
321
        with open(self.real_device, 'r') as source:
322
            with open(outfile, "w") as dest:
319

  
320
        with open(self.real_device, 'r') as src:
321
            with open(outfile, "w") as dst:
323 322
                left = self.size
324 323
                offset = 0
325 324
                progressbar.next()
326 325
                while left > 0:
327 326
                    length = min(left, blocksize)
328
                    sent = sendfile(dest.fileno(), source.fileno(), offset,
329
                                                                        length)
327
                    sent = sendfile(dst.fileno(), src.fileno(), offset, length)
330 328
                    offset += sent
331 329
                    left -= sent
332 330
                    progressbar.goto((self.size - left) // 2 ** 20)

Also available in: Unified diff