Skip to content

Commit 2c15eda

Browse files
Merge pull request #9225 from ThomasWaldmann/archive-cwd-master
info: show cwd at the time of backup creation, fixes #6191
2 parents d819cd3 + 3c2afeb commit 2c15eda

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

src/borg/archive.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ def info(self):
622622
else:
623623
info |= {
624624
"command_line": self.metadata.command_line,
625+
"cwd": self.metadata.get("cwd", ""),
625626
"hostname": self.metadata.hostname,
626627
"username": self.metadata.username,
627628
"comment": self.metadata.get("comment", ""),
@@ -692,6 +693,7 @@ def save(self, name=None, comment=None, timestamp=None, stats=None, additional_m
692693
"tags": list(sorted(self.tags)),
693694
"item_ptrs": item_ptrs, # see #1473
694695
"command_line": join_cmd(sys.argv),
696+
"cwd": self.cwd,
695697
"hostname": hostname,
696698
"username": getuser(),
697699
"time": start.isoformat(timespec="microseconds"),

src/borg/archiver/info_cmd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def do_info(self, args, repository, manifest, cache):
4646
Time (end): {end}
4747
Duration: {duration}
4848
Command line: {command_line}
49+
Working Directory: {cwd}
4950
Number of files: {stats[nfiles]}
5051
Original size: {stats[original_size]}
5152
"""

src/borg/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'recreate_source_id', 'recreate_args', 'recreate_partial_chunks', # used in 1.1.0b1 .. b2
2222
'size', 'nfiles',
2323
'size_parts', 'nfiles_parts', # legacy v1 archives
24+
'cwd',
2425
])
2526
# fmt: on
2627

src/borg/item.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,15 @@ cdef class ArchiveItem(PropDict):
523523
nfiles = PropDictProperty(int)
524524
size_parts = PropDictProperty(int) # legacy only
525525
nfiles_parts = PropDictProperty(int) # legacy only
526+
cwd = PropDictProperty(str, 'surrogate-escaped str')
526527

527528
def update_internal(self, d):
528529
# legacy support for migration (data from old msgpacks comes in as bytes always, but sometimes we want str)
529530
for k, v in list(d.items()):
530531
k = fix_key(d, k)
531532
if k == 'version':
532533
assert isinstance(v, int)
533-
if k in ('name', 'hostname', 'username', 'comment'):
534+
if k in ('name', 'hostname', 'username', 'comment', 'cwd'):
534535
v = fix_str_value(d, k)
535536
if k in ('time', 'time_end'):
536537
v = fix_str_value(d, k, 'replace')

src/borg/testsuite/archiver/info_cmd_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
from ...constants import * # NOQA
5+
from .. import changedir
56
from . import cmd, checkts, create_regular_file, generate_archiver_tests, RK_ENCRYPTION
67

78
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):
4647
assert info_repo["archives"] == []
4748
info_repo = json.loads(cmd(archiver, "info", "--json", "--last=1"))
4849
assert info_repo["archives"] == []
50+
51+
52+
def test_info_working_directory(archivers, request):
53+
archiver = request.getfixturevalue(archivers)
54+
# create a file in input and create the archive from inside the input directory
55+
create_regular_file(archiver.input_path, "file1", size=1)
56+
cmd(archiver, "repo-create", RK_ENCRYPTION)
57+
expected_cwd = os.path.abspath(archiver.input_path)
58+
with changedir(archiver.input_path):
59+
cmd(archiver, "create", "test", ".")
60+
info_archive = cmd(archiver, "info", "-a", "test")
61+
assert f"Working Directory: {expected_cwd}" in info_archive

0 commit comments

Comments
 (0)