legacy: move borg1 hardlink helpers to borg.legacy.helpers, refs #9556

This commit is contained in:
Mrityunjay Raj 2026-05-23 13:27:35 +05:30
parent 985d6f0ab0
commit 180130ba4e
3 changed files with 16 additions and 11 deletions

View file

@ -442,15 +442,6 @@ class HardLinkManager:
self.id_type = id_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)
def borg1_hardlink_master(self, item): # legacy
return item.get("hardlink_master", False) and "source" not in item and self.borg1_hardlinkable(item.mode)
def borg1_hardlink_slave(self, item): # legacy
return "source" in item and self.borg1_hardlinkable(item.mode)
def hardlink_id_from_path(self, path):
"""compute a hard link id from a path"""
assert isinstance(path, str)

View file

@ -0,0 +1,13 @@
import stat
def borg1_hardlinkable(mode):
return stat.S_ISREG(mode) or stat.S_ISBLK(mode) or stat.S_ISCHR(mode) or stat.S_ISFIFO(mode)
def borg1_hardlink_master(item):
return item.get("hardlink_master", False) and "source" not in item and borg1_hardlinkable(item.mode)
def borg1_hardlink_slave(item):
return "source" in item and borg1_hardlinkable(item.mode)

View file

@ -6,6 +6,7 @@ from ..compress import ZLIB, ZLIB_legacy, ObfuscateSize
from ..helpers import HardLinkManager, join_cmd
from ..item import Item
from ..logger import create_logger
from .helpers import borg1_hardlink_master, borg1_hardlink_slave
logger = create_logger(__name__)
@ -47,10 +48,10 @@ class UpgraderFrom12To20:
"acl_extended",
}
if self.hlm.borg1_hardlink_master(item):
if borg1_hardlink_master(item):
item.hlid = hlid = self.hlm.hardlink_id_from_path(item.path)
self.hlm.remember(id=hlid, info=item.get("chunks"))
elif self.hlm.borg1_hardlink_slave(item):
elif borg1_hardlink_slave(item):
item.hlid = hlid = self.hlm.hardlink_id_from_path(item.source)
chunks = self.hlm.retrieve(id=hlid)
if chunks is not None: