summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurizio Lombardi <mlombard@redhat.com>2020-11-23 19:04:25 +0100
committerGitHub <noreply@github.com>2020-11-23 19:04:25 +0100
commitaf9f5f679d37d91469a73226605d827a4986bcff (patch)
treeba2aa1430298d0e86488fb09c673fa1c440b8fb1
parent2c3eccac082a2980aaed371a1fdf0efc6a49dd59 (diff)
parent3176671662bda79d4b4059b8cc22b4b31a6547e0 (diff)
downloadtargetcli-af9f5f679d37d91469a73226605d827a4986bcff.tar.gz
Merge pull request #177 from maurizio-lombardi/sparse
fileio backstore: fix sparse file creation
-rw-r--r--targetcli/ui_backstore.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py
index 8692f22..9bc0c58 100644
--- a/targetcli/ui_backstore.py
+++ b/targetcli/ui_backstore.py
@@ -423,17 +423,17 @@ class UIFileIOBackstore(UIBackstore):
raise ExecutionError("Could not open %s" % filename)
try:
if sparse:
+ os.ftruncate(f.fileno(), size)
+ else:
+ self.shell.log.info("Writing %d bytes" % size)
try:
+ # Prior to version 3.3, Python does not provide fallocate
os.posix_fallocate(f.fileno(), 0, size)
except AttributeError:
- # Prior to version 3.3, Python does not provide fallocate
- os.ftruncate(f.fileno(), size)
- else:
- self.shell.log.info("Writing %d bytes" % size)
- while size > 0:
- write_size = min(size, 1024)
- f.write("\0" * write_size)
- size -= write_size
+ while size > 0:
+ write_size = min(size, 1024)
+ f.write("\0" * write_size)
+ size -= write_size
except (OSError, IOError):
os.remove(filename)
raise ExecutionError("Could not expand file to %d bytes" % size)