Merge pull request #9225 from ThomasWaldmann/archive-cwd-master
Some checks are pending
Lint / lint (push) Waiting to run
CI / lint (push) Waiting to run
CI / security (push) Waiting to run
CI / asan_ubsan (push) Blocked by required conditions
CI / native_tests (push) Blocked by required conditions
CI / vm_tests (Haiku, false, haiku, r1beta5) (push) Blocked by required conditions
CI / vm_tests (NetBSD, false, netbsd, 10.1) (push) Blocked by required conditions
CI / vm_tests (OpenBSD, false, openbsd, 7.7) (push) Blocked by required conditions
CI / vm_tests (borg-freebsd-14-x86_64-gh, FreeBSD, true, freebsd, 14.3) (push) Blocked by required conditions
CI / windows_tests (push) Blocked by required conditions
CodeQL / Analyze (push) Waiting to run

info: show cwd at the time of backup creation, fixes #6191
This commit is contained in:
TW 2025-12-16 03:24:57 +01:00 committed by GitHub
commit 2c15eda7ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 1 deletions

View file

@ -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"),

View file

@ -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]}
"""

View file

@ -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

View file

@ -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')

View file

@ -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