浏览代码

Escape cmdline arguments that have spaces in them

`borg info` command shows the command line that was used to create the archive.
If the command line has arguments with spaces in them the printed command will
not work. This commit will escape these arguments by enclosing it to quotation
marks.
Lauri Niskanen 9 年之前
父节点
当前提交
d0c56a9a69
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      borg/archiver.py

+ 4 - 1
borg/archiver.py

@@ -725,6 +725,9 @@ class Archiver:
     @with_archive
     def do_info(self, args, repository, manifest, key, archive, cache):
         """Show archive details such as disk space used"""
+        def format_cmdline(cmdline):
+            return remove_surrogates(' '.join(shlex.quote(x) for x in cmdline))
+
         stats = archive.calc_stats(cache)
         print('Name:', archive.name)
         print('Fingerprint: %s' % hexlify(archive.id).decode('ascii'))
@@ -732,7 +735,7 @@ class Archiver:
         print('Username:', archive.metadata[b'username'])
         print('Time (start): %s' % format_time(to_localtime(archive.ts)))
         print('Time (end):   %s' % format_time(to_localtime(archive.ts_end)))
-        print('Command line:', remove_surrogates(' '.join(archive.metadata[b'cmdline'])))
+        print('Command line:', format_cmdline(archive.metadata[b'cmdline']))
         print('Number of files: %d' % stats.nfiles)
         print()
         print(str(stats))