Simone Tiraboschi has uploaded a new change for review.

Change subject: upload: use low level copy to enable progress bar creation
......................................................................

upload: use low level copy to enable progress bar creation

Using python code to copy the file to enable the
implementation of a custo progress bar.

https://bugzilla.redhat.com/1077235

Change-Id: I029e1d59fa51cb97514e5c3f4e9d35c2d2b67abe
Signed-off-by: Simone Tiraboschi <stira...@redhat.com>
---
M src/__main__.py
1 file changed, 25 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-iso-uploader 
refs/changes/85/37285/1

diff --git a/src/__main__.py b/src/__main__.py
index 841d81c..8af853e 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -797,6 +797,30 @@
         )
         return (dir_size, file_size)
 
+    def copyfileobj_sparse(
+            self,
+            fsrc,
+            fdst,
+            length=16*1024,
+            make_sparse=True
+    ):
+        """
+        copy data from file-like object fsrc to file-like object fdst
+        like shutils.copyfileobj does but supporting also
+        sparse file
+        """
+        while 1:
+            buf = fsrc.read(length)
+            if not buf:
+                break
+            if make_sparse and buf == '\0'*len(buf):
+                fdst.seek(len(buf), os.SEEK_CUR)
+            else:
+                fdst.write(buf)
+        if make_sparse:
+            # Make sure the file ends where it should, even if padded out.
+            fdst.truncate()
+
     def copy_file(self, src_file_name, dest_file_name, uid, gid):
         """
         Copy a file from source to dest via file handles.  The destination
@@ -813,7 +837,7 @@
             os.setegid(gid)
             os.seteuid(uid)
             dest = open(dest_file_name, 'w')
-            shutil.copyfileobj(src, dest)
+            self.copyfileobj_sparse(src, dest)
         except Exception, e:
             retVal = False
             logging.error(_("Problem copying %s to %s.  Message: %s" %


-- 
To view, visit http://gerrit.ovirt.org/37285
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I029e1d59fa51cb97514e5c3f4e9d35c2d2b67abe
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-iso-uploader
Gerrit-Branch: master
Gerrit-Owner: Simone Tiraboschi <stira...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to