Jelajahi Sumber

Merge pull request #9209 from ThomasWaldmann/fix-9208

Fix misc. borg transfer issues
TW 1 hari lalu
induk
melakukan
2152e1e3a9
4 mengubah file dengan 10 tambahan dan 4 penghapusan
  1. 5 1
      src/borg/archiver/transfer_cmd.py
  2. 1 1
      src/borg/helpers/fs.py
  3. 1 1
      src/borg/manifest.py
  4. 3 1
      src/borg/upgrade.py

+ 5 - 1
src/borg/archiver/transfer_cmd.py

@@ -10,6 +10,7 @@ from ..helpers import Error
 from ..helpers import location_validator, Location, archivename_validator, comment_validator
 from ..helpers import format_file_size, bin_to_hex
 from ..helpers import ChunkerParams, ChunkIteratorFileWrapper
+from ..item import ChunkListEntry
 from ..manifest import Manifest
 from ..legacyrepository import LegacyRepository
 from ..repository import Repository
@@ -84,7 +85,10 @@ def transfer_chunks(
                         # A missing correct chunk in other_repository (source) will result in
                         # a missing chunk in repository (destination).
                         # We do NOT want to transfer all-zero replacement chunks from Borg 1 repositories.
-                        pass
+                        # But we want to have a correct chunks list entry. That will be useful in case the
+                        # chunk reappears, and also we could dynamically generate an all-zero replacement
+                        # of the correct size for reading / extracting, if desired.
+                        chunk_entry = ChunkListEntry(chunk_id, size)
                     else:
                         if recompress == "never":
                             # Keep the compressed payload the same; verify via assert_id (that will

+ 1 - 1
src/borg/helpers/fs.py

@@ -346,7 +346,7 @@ class HardLinkManager:
     def __init__(self, *, id_type, info_type):
         self._map = {}
         self.id_type = id_type
-        self.info_type = info_type
+        self.info_type = info_type  # can be a single type or a tuple of types
 
     def borg1_hardlinkable(self, mode):  # legacy
         return stat.S_ISREG(mode) or stat.S_ISBLK(mode) or stat.S_ISCHR(mode) or stat.S_ISFIFO(mode)

+ 1 - 1
src/borg/manifest.py

@@ -151,7 +151,7 @@ class Archives:
                 hostname=archive_item.hostname,
                 size=archive_item.get("size", 0),
                 nfiles=archive_item.get("nfiles", 0),
-                comment=archive_item.comment,  # not always present?
+                comment=archive_item.get("comment", ""),
                 tags=tuple(sorted(getattr(archive_item, "tags", []))),  # must be hashable
             )
         return metadata

+ 3 - 1
src/borg/upgrade.py

@@ -1,4 +1,5 @@
 from struct import Struct
+from types import NoneType
 
 from .constants import REQUIRED_ITEM_KEYS, CH_BUZHASH
 from .compress import ZLIB, ZLIB_legacy, ObfuscateSize
@@ -53,7 +54,8 @@ class UpgraderFrom12To20:
 
     def new_archive(self, *, archive):
         self.archive = archive
-        self.hlm = HardLinkManager(id_type=bytes, info_type=list)  # hlid -> chunks_correct
+        # hlid -> chunks_correct list (or None, for contentless hardlinks)
+        self.hlm = HardLinkManager(id_type=bytes, info_type=(list, NoneType))
 
     def upgrade_item(self, *, item):
         """Upgrades the item as needed and removes legacy data."""