]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: call os.ftruncate instead of running truncate
authorEd Bartosh <ed.bartosh@linux.intel.com>
Wed, 2 Nov 2016 20:33:07 +0000 (22:33 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 6 Nov 2016 23:35:23 +0000 (23:35 +0000)
Replaced running of truncate utility with the standard library
call os.ftruncate

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/lib/wic/imager/direct.py
scripts/lib/wic/partition.py

index edf5e5d2214f8e78b6c2a98d7f6cd45fcc0065c4..2bedef08d6450096c786def6f75a9ee53fcd4b3b 100644 (file)
@@ -56,8 +56,9 @@ class DiskImage():
         if self.created:
             return
         # create sparse disk image
-        cmd = "truncate %s -s %s" % (self.device, self.size)
-        exec_cmd(cmd)
+        with open(self.device, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), self.size)
+
         self.created = True
 
 class DirectImageCreator(BaseImageCreator):
index 90f65a1e3976a5460cd1b265b238168cce22781f..89c33ab8b7d54bb14678b2e07e706e3feb6ae57a 100644 (file)
@@ -217,7 +217,8 @@ class Partition():
         msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                     (extra_blocks, self.mountpoint, rootfs_size))
 
-        exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
+        with open(rootfs, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), rootfs_size * 1024)
 
         extra_imagecmd = "-i 8192"
 
@@ -250,7 +251,8 @@ class Partition():
         msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                     (extra_blocks, self.mountpoint, rootfs_size))
 
-        exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
+        with open(rootfs, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), rootfs_size * 1024)
 
         label_str = ""
         if self.label:
@@ -305,7 +307,8 @@ class Partition():
         """
         Prepare an empty ext2/3/4 partition.
         """
-        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
+        with open(rootfs, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), rootfs_size * 1024)
 
         extra_imagecmd = "-i 8192"
 
@@ -322,7 +325,8 @@ class Partition():
         """
         Prepare an empty btrfs partition.
         """
-        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
+        with open(rootfs, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), rootfs_size * 1024)
 
         label_str = ""
         if self.label:
@@ -383,7 +387,8 @@ class Partition():
         """
         path = "%s/fs.%s" % (cr_workdir, self.fstype)
 
-        exec_cmd("truncate %s -s %d" % (path, self.size * 1024))
+        with open(path, 'w') as sparse:
+            os.ftruncate(sparse.fileno(), self.size * 1024)
 
         import uuid
         label_str = ""