[blivet:master 05/20] Avoid using Size constant in FileDevice._create().
mulhern
amulhern at redhat.com
Tue Dec 23 23:42:18 UTC 2014
It makes the code a little bit awkward and busy and the name MiB
will conflict with some size constants defined in subsequent patch.
New code is an order of magnitude more efficient, which is a bonus.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devices/file.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/blivet/devices/file.py b/blivet/devices/file.py
index da231c5..628853d 100644
--- a/blivet/devices/file.py
+++ b/blivet/devices/file.py
@@ -24,7 +24,6 @@ import os
from .. import util
from ..storage_log import log_method_call
-from ..size import Size
import logging
log = logging.getLogger("blivet")
@@ -98,12 +97,11 @@ class FileDevice(StorageDevice):
fd = os.open(self.path, os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
# all this fuss is so we write the zeros 1MiB at a time
zero = "\0"
- MiB = Size("1 MiB")
- count = int(self.size.convertTo(spec="MiB"))
- rem = self.size % MiB
+ block_size = 1024 ** 2
+ (count, rem) = divmod(int(self.size), block_size)
for _n in range(count):
- os.write(fd, zero * MiB)
+ os.write(fd, zero * block_size)
if rem:
# write out however many more zeros it takes to hit our size target
--
1.9.3
More information about the anaconda-patches
mailing list