mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-13 07:33:47 +00:00
Merge pull request #511 from ThomasWaldmann/progress-update-quicker
output progress indication from inner loop, fixes #500
This commit is contained in:
commit
4639617e2b
2 changed files with 23 additions and 18 deletions
|
@ -143,7 +143,6 @@ class Archive:
|
||||||
self.hard_links = {}
|
self.hard_links = {}
|
||||||
self.stats = Statistics()
|
self.stats = Statistics()
|
||||||
self.show_progress = progress
|
self.show_progress = progress
|
||||||
self.last_progress = time.time()
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.checkpoint_interval = checkpoint_interval
|
self.checkpoint_interval = checkpoint_interval
|
||||||
self.numeric_owner = numeric_owner
|
self.numeric_owner = numeric_owner
|
||||||
|
@ -215,9 +214,8 @@ Number of files: {0.stats.nfiles}'''.format(self)
|
||||||
unknown_keys = set(item) - ITEM_KEYS
|
unknown_keys = set(item) - ITEM_KEYS
|
||||||
assert not unknown_keys, ('unknown item metadata keys detected, please update ITEM_KEYS: %s',
|
assert not unknown_keys, ('unknown item metadata keys detected, please update ITEM_KEYS: %s',
|
||||||
','.join(k.decode('ascii') for k in unknown_keys))
|
','.join(k.decode('ascii') for k in unknown_keys))
|
||||||
if self.show_progress and time.time() - self.last_progress > 0.2:
|
if self.show_progress:
|
||||||
self.stats.show_progress(item=item)
|
self.stats.show_progress(item=item, dt=0.2)
|
||||||
self.last_progress = time.time()
|
|
||||||
self.items_buffer.add(item)
|
self.items_buffer.add(item)
|
||||||
if time.time() - self.last_checkpoint > self.checkpoint_interval:
|
if time.time() - self.last_checkpoint > self.checkpoint_interval:
|
||||||
self.write_checkpoint()
|
self.write_checkpoint()
|
||||||
|
@ -526,6 +524,7 @@ Number of files: {0.stats.nfiles}'''.format(self)
|
||||||
status = 'U' # regular file, unchanged
|
status = 'U' # regular file, unchanged
|
||||||
else:
|
else:
|
||||||
status = 'A' # regular file, added
|
status = 'A' # regular file, added
|
||||||
|
item = {b'path': safe_path}
|
||||||
# Only chunkify the file if needed
|
# Only chunkify the file if needed
|
||||||
if chunks is None:
|
if chunks is None:
|
||||||
fh = Archive._open_rb(path, st)
|
fh = Archive._open_rb(path, st)
|
||||||
|
@ -533,9 +532,11 @@ Number of files: {0.stats.nfiles}'''.format(self)
|
||||||
chunks = []
|
chunks = []
|
||||||
for chunk in self.chunker.chunkify(fd, fh):
|
for chunk in self.chunker.chunkify(fd, fh):
|
||||||
chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats))
|
chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats))
|
||||||
|
if self.show_progress:
|
||||||
|
self.stats.show_progress(item=item, dt=0.2)
|
||||||
cache.memorize_file(path_hash, st, [c[0] for c in chunks])
|
cache.memorize_file(path_hash, st, [c[0] for c in chunks])
|
||||||
status = status or 'M' # regular file, modified (if not 'A' already)
|
status = status or 'M' # regular file, modified (if not 'A' already)
|
||||||
item = {b'path': safe_path, b'chunks': chunks}
|
item[b'chunks'] = chunks
|
||||||
item.update(self.stat_attrs(st, path))
|
item.update(self.stat_attrs(st, path))
|
||||||
self.stats.nfiles += 1
|
self.stats.nfiles += 1
|
||||||
self.add_item(item)
|
self.add_item(item)
|
||||||
|
|
|
@ -162,6 +162,7 @@ class Statistics:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.osize = self.csize = self.usize = self.nfiles = 0
|
self.osize = self.csize = self.usize = self.nfiles = 0
|
||||||
|
self.last_progress = 0 # timestamp when last progress was shown
|
||||||
|
|
||||||
def update(self, size, csize, unique):
|
def update(self, size, csize, unique):
|
||||||
self.osize += size
|
self.osize += size
|
||||||
|
@ -191,7 +192,10 @@ class Statistics:
|
||||||
def csize_fmt(self):
|
def csize_fmt(self):
|
||||||
return format_file_size(self.csize)
|
return format_file_size(self.csize)
|
||||||
|
|
||||||
def show_progress(self, item=None, final=False, stream=None):
|
def show_progress(self, item=None, final=False, stream=None, dt=None):
|
||||||
|
now = time.time()
|
||||||
|
if dt is None or now - self.last_progress > dt:
|
||||||
|
self.last_progress = now
|
||||||
columns, lines = get_terminal_size()
|
columns, lines = get_terminal_size()
|
||||||
if not final:
|
if not final:
|
||||||
msg = '{0.osize_fmt} O {0.csize_fmt} C {0.usize_fmt} D {0.nfiles} N '.format(self)
|
msg = '{0.osize_fmt} O {0.csize_fmt} C {0.usize_fmt} D {0.nfiles} N '.format(self)
|
||||||
|
|
Loading…
Add table
Reference in a new issue