diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-11-02 22:33:07 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-11-06 23:35:36 +0000 |
commit | c8669749e37fe865c197c98d5671d9de176ff4dd (patch) | |
tree | 4c216bf32236e9ef85d6b88e0b893f9b0bd5925a /scripts | |
parent | eb345ca720e5b4dbc3f4197913a7a3d841fe9bc5 (diff) | |
download | openembedded-core-contrib-c8669749e37fe865c197c98d5671d9de176ff4dd.tar.gz |
wic: call os.ftruncate instead of running truncate
Replaced running of truncate utility with the standard library
call os.ftruncate
(From OE-Core rev: 1ba6101ceaee354816e690d44bc9a5dd8dcf4011)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/wic/imager/direct.py | 5 | ||||
-rw-r--r-- | scripts/lib/wic/partition.py | 15 |
2 files changed, 13 insertions, 7 deletions
diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py index edf5e5d221..2bedef08d6 100644 --- a/scripts/lib/wic/imager/direct.py +++ b/scripts/lib/wic/imager/direct.py @@ -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): diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index 90f65a1e39..89c33ab8b7 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py @@ -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 = "" |