mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-29 19:26:40 +00:00
Move code block for the write() function at do_list()
This commit is contained in:
parent
9a64835b4d
commit
0942bcd1b4
1 changed files with 8 additions and 7 deletions
|
@ -738,6 +738,14 @@ def do_mount(self, args, repository, manifest, key):
|
|||
@with_repository()
|
||||
def do_list(self, args, repository, manifest, key):
|
||||
"""List archive or repository contents"""
|
||||
if not hasattr(sys.stdout, 'buffer'):
|
||||
# This is a shim for supporting unit tests replacing sys.stdout with e.g. StringIO,
|
||||
# which doesn't have an underlying buffer (= lower file object).
|
||||
def write(bytestring):
|
||||
sys.stdout.write(bytestring.decode('utf-8', errors='replace'))
|
||||
else:
|
||||
write = sys.stdout.buffer.write
|
||||
|
||||
if args.location.archive:
|
||||
matcher, _ = self.build_matcher(args.excludes, args.paths)
|
||||
with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
|
||||
|
@ -751,13 +759,6 @@ def do_list(self, args, repository, manifest, key):
|
|||
format = "{mode} {user:6} {group:6} {size:8} {isomtime} {path}{extra}{NL}"
|
||||
formatter = ItemFormatter(archive, format)
|
||||
|
||||
if not hasattr(sys.stdout, 'buffer'):
|
||||
# This is a shim for supporting unit tests replacing sys.stdout with e.g. StringIO,
|
||||
# which doesn't have an underlying buffer (= lower file object).
|
||||
def write(bytestring):
|
||||
sys.stdout.write(bytestring.decode('utf-8', errors='replace'))
|
||||
else:
|
||||
write = sys.stdout.buffer.write
|
||||
for item in archive.iter_items(lambda item: matcher.match(item.path)):
|
||||
write(safe_encode(formatter.format_item(item)))
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue