diff --git a/src/borg/archive.py b/src/borg/archive.py index 674bed44f5..79ff01d967 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -622,6 +622,7 @@ def info(self): 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 @@ def save(self, name=None, comment=None, timestamp=None, stats=None, additional_m "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"), diff --git a/src/borg/archiver/info_cmd.py b/src/borg/archiver/info_cmd.py index 30b823bf65..5209bae155 100644 --- a/src/borg/archiver/info_cmd.py +++ b/src/borg/archiver/info_cmd.py @@ -46,6 +46,7 @@ def do_info(self, args, repository, manifest, cache): Time (end): {end} Duration: {duration} Command line: {command_line} + Working Directory: {cwd} Number of files: {stats[nfiles]} Original size: {stats[original_size]} """ diff --git a/src/borg/constants.py b/src/borg/constants.py index 092ca771f9..bbbbc56103 100644 --- a/src/borg/constants.py +++ b/src/borg/constants.py @@ -21,6 +21,7 @@ '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 diff --git a/src/borg/item.pyx b/src/borg/item.pyx index 3dcabefc28..e477473f5d 100644 --- a/src/borg/item.pyx +++ b/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') diff --git a/src/borg/testsuite/archiver/info_cmd_test.py b/src/borg/testsuite/archiver/info_cmd_test.py index 550bd8d71b..f30d6fb66f 100644 --- a/src/borg/testsuite/archiver/info_cmd_test.py +++ b/src/borg/testsuite/archiver/info_cmd_test.py @@ -2,6 +2,7 @@ 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