From df64986fea91c9103baa1a07c5021cc0b4bb7a6f Mon Sep 17 00:00:00 2001 From: notEvil Date: Tue, 22 Sep 2015 08:03:57 +0200 Subject: fix progress bar regression --- ranger/core/loader.py | 19 +++++++++++++------ ranger/ext/shutil_generatorized.py | 24 ++++++++++++------------ 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: -- cgit 1.4.1-2-gfad0