From df57d37273498a7c520cd0f26e3ce0c19098af9f Mon Sep 17 00:00:00 2001 From: relikd Date: Tue, 9 Sep 2025 00:14:01 +0200 Subject: [PATCH] ref: File.isMachO --- brew.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/brew.py b/brew.py index 4148c56..d49dab4 100755 --- a/brew.py +++ b/brew.py @@ -1398,17 +1398,7 @@ class LocalPackageVersion: Log.error('not a brew-package directory', self.path, summary=True) return - for base, dirs, files in os.walk(self.path): - for file in files: - fname = os.path.join(base, file) - if os.path.islink(fname): - Fixer.symlink(fname) - continue - # magic number check for Mach-O - with open(fname, 'rb') as fp: - if fp.read(4) != b'\xcf\xfa\xed\xfe': - continue - Fixer.dylib(fname) + Fixer.run(self.path) # ----------------------------------- @@ -1882,6 +1872,18 @@ class InstallQueue: # ----------------------------------- class Fixer: + @staticmethod + def run(path: str) -> None: + for base, dirs, files in os.walk(path): + for file in files: + fname = os.path.join(base, file) + if os.path.islink(fname): + Fixer.symlink(fname) + continue + + if File.isMachO(fname): + Fixer.dylib(fname) + @staticmethod def symlink(fname: str) -> None: ''' Fix time on symlink, copy time from target link ''' @@ -2435,6 +2437,12 @@ class RubyParser: # ----------------------------------- class File: + @staticmethod + def isMachO(fname: str) -> bool: + # magic number check for Mach-O + with open(fname, 'rb') as fp: + return fp.read(4) == b'\xcf\xfa\xed\xfe' + @staticmethod def isOutdated(fname: str, maxage: int) -> bool: ''' Check if `fname` is older than `maxage` '''