소스 검색

Merge pull request #9225 from ThomasWaldmann/archive-cwd-master

info: show cwd at the time of backup creation, fixes #6191
TW 16 시간 전
부모
커밋
2c15eda7ac
5개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 0
      src/borg/archive.py
  2. 1 0
      src/borg/archiver/info_cmd.py
  3. 1 0
      src/borg/constants.py
  4. 2 1
      src/borg/item.pyx
  5. 13 0
      src/borg/testsuite/archiver/info_cmd_test.py

+ 2 - 0
src/borg/archive.py

@@ -622,6 +622,7 @@ class Archive:
         else:
             info |= {
                 "command_line": self.metadata.command_line,
+                "cwd": self.metadata.get("cwd", ""),
                 "hostname": self.metadata.hostname,
                 "username": self.metadata.username,
                 "comment": self.metadata.get("comment", ""),
@@ -692,6 +693,7 @@ Duration: {0.duration}
             "tags": list(sorted(self.tags)),
             "item_ptrs": item_ptrs,  # see #1473
             "command_line": join_cmd(sys.argv),
+            "cwd": self.cwd,
             "hostname": hostname,
             "username": getuser(),
             "time": start.isoformat(timespec="microseconds"),

+ 1 - 0
src/borg/archiver/info_cmd.py

@@ -46,6 +46,7 @@ class InfoMixIn:
                 Time (end): {end}
                 Duration: {duration}
                 Command line: {command_line}
+                Working Directory: {cwd}
                 Number of files: {stats[nfiles]}
                 Original size: {stats[original_size]}
                 """

+ 1 - 0
src/borg/constants.py

@@ -21,6 +21,7 @@ ARCHIVE_KEYS = frozenset(['version', 'name', 'hostname', 'username', 'time', 'ti
                           'recreate_source_id', 'recreate_args', 'recreate_partial_chunks',  # used in 1.1.0b1 .. b2
                           'size', 'nfiles',
                           'size_parts', 'nfiles_parts',  # legacy v1 archives
+                          'cwd',
                           ])
 # fmt: on
 

+ 2 - 1
src/borg/item.pyx

@@ -523,6 +523,7 @@ cdef class ArchiveItem(PropDict):
     nfiles = PropDictProperty(int)
     size_parts = PropDictProperty(int)  # legacy only
     nfiles_parts = PropDictProperty(int)  # legacy only
+    cwd = PropDictProperty(str, 'surrogate-escaped str')
 
     def update_internal(self, d):
         # legacy support for migration (data from old msgpacks comes in as bytes always, but sometimes we want str)
@@ -530,7 +531,7 @@ cdef class ArchiveItem(PropDict):
             k = fix_key(d, k)
             if k == 'version':
                 assert isinstance(v, int)
-            if k in ('name', 'hostname', 'username', 'comment'):
+            if k in ('name', 'hostname', 'username', 'comment', 'cwd'):
                 v = fix_str_value(d, k)
             if k in ('time', 'time_end'):
                 v = fix_str_value(d, k, 'replace')

+ 13 - 0
src/borg/testsuite/archiver/info_cmd_test.py

@@ -2,6 +2,7 @@ import json
 import os
 
 from ...constants import *  # NOQA
+from .. import changedir
 from . import cmd, checkts, create_regular_file, generate_archiver_tests, RK_ENCRYPTION
 
 pytest_generate_tests = lambda metafunc: generate_archiver_tests(metafunc, kinds="local,remote,binary")  # NOQA
@@ -46,3 +47,15 @@ def test_info_json_of_empty_archive(archivers, request):
     assert info_repo["archives"] == []
     info_repo = json.loads(cmd(archiver, "info", "--json", "--last=1"))
     assert info_repo["archives"] == []
+
+
+def test_info_working_directory(archivers, request):
+    archiver = request.getfixturevalue(archivers)
+    # create a file in input and create the archive from inside the input directory
+    create_regular_file(archiver.input_path, "file1", size=1)
+    cmd(archiver, "repo-create", RK_ENCRYPTION)
+    expected_cwd = os.path.abspath(archiver.input_path)
+    with changedir(archiver.input_path):
+        cmd(archiver, "create", "test", ".")
+    info_archive = cmd(archiver, "info", "-a", "test")
+    assert f"Working Directory: {expected_cwd}" in info_archive