about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornotEvil <a_rappold@gmx.at>2015-09-22 08:03:57 +0200
committerhut <hut@lepus.uberspace.de>2015-09-22 18:41:24 +0200
commitdf64986fea91c9103baa1a07c5021cc0b4bb7a6f (patch)
tree81639947c614eeb1d14738906541e22bf5ceb53b
parentf33ea2bc7b12f77f28f7e6b1017ddeca2c2b6335 (diff)
downloadranger-df64986fea91c9103baa1a07c5021cc0b4bb7a6f.tar.gz
fix progress bar regression
-rw-r--r--ranger/core/loader.py19
-rw-r--r--ranger/ext/shutil_generatorized.py24
2 files changed, 25 insertions, 18 deletions
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index e672bbed..411b16ec 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -77,6 +77,7 @@ class CopyLoader(Loadable, FileManagerAware):
             # TODO: Don't calculate size when renaming (needs detection)
             bytes_per_tick = shutil_g.BLOCK_SIZE
             size = max(1, self._calculate_size(bytes_per_tick))
+            done = 0
             if self.do_cut:
                 self.original_copy_buffer.clear()
                 if len(self.copy_buffer) == 1:
@@ -91,11 +92,13 @@ class CopyLoader(Loadable, FileManagerAware):
                             self.fm.tags.tags[tf.replace(f.path, self.original_path \
                                     + '/' + f.basename)] = tag
                             self.fm.tags.dump()
-                    for done in shutil_g.move(src=f.path,
+                    d = 0
+                    for d in shutil_g.move(src=f.path,
                             dst=self.original_path,
                             overwrite=self.overwrite):
-                        self.percent = float(done) / size * 100.
+                        self.percent = float(done + d) / size * 100.
                         yield
+                    done += d
             else:
                 if len(self.copy_buffer) == 1:
                     self.description = "copying: " + self.one_file.path
@@ -103,18 +106,22 @@ class CopyLoader(Loadable, FileManagerAware):
                     self.description = "copying files from: " + self.one_file.dirname
                 for f in self.copy_buffer:
                     if os.path.isdir(f.path) and not os.path.islink(f.path):
-                        for done in shutil_g.copytree(src=f.path,
+                        d = 0
+                        for d in shutil_g.copytree(src=f.path,
                                 dst=os.path.join(self.original_path, f.basename),
                                 symlinks=True,
                                 overwrite=self.overwrite):
-                            self.percent = float(done) / size * 100.
+                            self.percent = float(done + d) / size * 100.
                             yield
+                        done += d
                     else:
-                        for done in shutil_g.copy2(f.path, self.original_path,
+                        d = 0
+                        for d in shutil_g.copy2(f.path, self.original_path,
                                 symlinks=True,
                                 overwrite=self.overwrite):
-                            self.percent = float(done) / size * 100.
+                            self.percent = float(done + d) / size * 100.
                             yield
+                        done += d
             cwd = self.fm.get_directory(self.original_path)
             cwd.load_content()
 
diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py
index 7515b491..6b63f4c7 100644
--- a/ranger/ext/shutil_generatorized.py
+++ b/ranger/ext/shutil_generatorized.py
@@ -30,14 +30,14 @@ except NameError:
 
 def copyfileobj(fsrc, fdst, length=BLOCK_SIZE):
     """copy data from file-like object fsrc to file-like object fdst"""
-    total = 0
+    done = 0
     while 1:
         buf = fsrc.read(length)
         if not buf:
             break
         fdst.write(buf)
-        total += len(buf)
-        yield total
+        done += len(buf)
+        yield done
 
 def _samefile(src, dst):
     # Macintosh, Unix.
@@ -167,7 +167,7 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False):
         if not overwrite:
             dst = get_safe_path(dst)
             os.makedirs(dst)
-    total = 0
+    done = 0
     for name in names:
         if name in ignored_names:
             continue
@@ -181,18 +181,18 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False):
                 os.symlink(linkto, dstname)
                 copystat(srcname, dstname)
             elif os.path.isdir(srcname):
-                done = 0
-                for done in copytree(srcname, dstname, symlinks,
+                d = 0
+                for d in copytree(srcname, dstname, symlinks,
                         ignore, overwrite):
-                    yield total + done
-                total += done
+                    yield done + d
+                done += d
             else:
                 # Will raise a SpecialFileError for unsupported file types
-                done = 0
-                for done in copy2(srcname, dstname,
+                d = 0
+                for d in copy2(srcname, dstname,
                         overwrite=overwrite, symlinks=symlinks):
-                    yield total + done
-                total += done
+                    yield done + d
+                done += d
         # catch the Error from the recursive copytree so that we can
         # continue with other files
         except Error as err: