Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ def save(self, name=None, comment=None, timestamp=None, stats=None, additional_m
stats = stats or self.stats
metadata |= {"size": stats.osize, "nfiles": stats.nfiles}
metadata |= additional_metadata or {}
if metadata.get("cwd") is None:
del metadata["cwd"]
metadata = ArchiveItem(metadata)
data = self.key.pack_metadata(metadata.as_dict())
self.id = self.repo_objs.id_hash(data)
Expand Down
1 change: 1 addition & 0 deletions src/borg/testsuite/archiver/transfer_cmd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def test_transfer_archive_metadata(archivers, request, monkeypatch):
assert dest_archive["hostname"] == source_archive["hostname"]
assert dest_archive["username"] == source_archive["username"]
assert dest_archive["command_line"] == source_archive["command_line"]
assert dest_archive["cwd"] == source_archive["cwd"]
assert dest_archive["duration"] == source_archive["duration"]
assert dest_archive["start"] == source_archive["start"]
assert dest_archive["end"] == source_archive["end"]
Expand Down
3 changes: 3 additions & 0 deletions src/borg/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def upgrade_archive_metadata(self, *, metadata):
):
if hasattr(metadata, attr):
new_metadata[attr] = getattr(metadata, attr)
new_metadata["cwd"] = getattr(metadata, "cwd", None) # None signals save() to leave cwd unset
rechunking = self.args.chunker_params is not None
if rechunking:
# if we are rechunking while transferring, we take the new chunker_params.
Expand Down Expand Up @@ -152,6 +153,8 @@ def upgrade_archive_metadata(self, *, metadata):
for attr in ("hostname", "username", "comment", "chunker_params"):
if hasattr(metadata, attr):
new_metadata[attr] = getattr(metadata, attr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, guess that solves it for borg 1.4 archives that do have the cwd metadata (borg 1.4.4+).

but what happens if an older archive gets transferred that does not have the cwd metadata, what will be and what should be in the resulting archive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review. I guess we shouldn't check cwd inside the for loop. After the loop, could we check it specifically, like getattr(metadata, "cwd", "")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm not sure if "" is the best choice here . would you prefer leaving cwd unset or is that fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can't know, having it unset might be the best choice. check if the code can cope with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out omitting cwd from additional_metadata wasn't enough . save() always falls back to self.cwd. Used None as a sentinel instead: upgraders pass cwd=None for archives without it, and save() drops the key when it sees None.

# if cwd is None, we want to drop it from metadata, so we set it to None here, and save() will drop it.
new_metadata["cwd"] = getattr(metadata, "cwd", None)
rechunking = self.args.chunker_params is not None
if rechunking:
# if we are rechunking while transferring, we take the new chunker_params.
Expand Down
Loading