ref: File.recursiveFiles

This commit is contained in:
relikd
2025-09-10 01:15:43 +02:00
parent 70409e4535
commit 8709725988

33
brew.py
View File

@@ -1920,20 +1920,18 @@ class InstallQueue:
class Fixer: class Fixer:
@staticmethod @staticmethod
def run(path: str) -> None: def run(path: str) -> None:
for base, dirs, files in os.walk(path): for fname in File.recursiveFiles(path):
for file in files: if os.path.islink(fname):
fname = os.path.join(base, file) Fixer.symlink(fname)
if os.path.islink(fname): continue
Fixer.symlink(fname)
continue
if File.isMachO(fname): if File.isMachO(fname):
Dylib(fname).fix() Dylib(fname).fix()
elif File.isBinary(fname): elif File.isBinary(fname):
pass # skip other binary (.a, .class, .png, ...) pass # skip other binary (.a, .class, .png, ...)
else: else:
# replace all @@homebrew@@ placeholders # replace all @@homebrew@@ placeholders
Fixer.inreplace(fname) Fixer.inreplace(fname)
@staticmethod @staticmethod
def symlink(fname: str) -> None: def symlink(fname: str) -> None:
@@ -2698,6 +2696,15 @@ class File:
with open(fname, 'a'): with open(fname, 'a'):
os.utime(fname, None) os.utime(fname, None)
@staticmethod
def recursiveFiles(path: str) -> Iterator[str]:
''' yield only files from `os.walk(path)` '''
if os.path.isdir(path):
for base, _, files in os.walk(path):
for file in files:
if file != '.DS_Store':
yield os.path.join(base, file)
@staticmethod @staticmethod
def folderSize(path: str) -> tuple[int, int]: def folderSize(path: str) -> tuple[int, int]:
'''Calculate total size of folder and all it's content (recursively)''' '''Calculate total size of folder and all it's content (recursively)'''