Skip to content

Commit

Permalink
Attempt fix for macOS (/private)/var/folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Oct 13, 2024
1 parent bf934fd commit 4a09cc5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pex/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,24 @@ def dir_hash(
# type: (...) -> None
"""Digest the contents of a directory in a reproducible manner."""

top = os.path.realpath(directory)

def iter_files():
# type: () -> Iterator[Text]
normpath = os.path.realpath(os.path.normpath(directory))
for root, dirs, files in os.walk(normpath):
for root, dirs, files in os.walk(top):
dirs[:] = [d for d in dirs if dir_filter(d)]
for f in files:
if file_filter(f):
yield os.path.relpath(os.path.join(root, f), normpath)
yield os.path.join(root, f)

names = sorted(iter_files())
file_paths = sorted(iter_files())

# Always use / as the path separator, since that's what zip uses.
hashed_names = [n.replace(os.sep, "/") for n in names]
hashed_names = [os.path.relpath(n, top).replace(os.sep, "/") for n in file_paths]
digest.update("".join(hashed_names).encode("utf-8"))

for name in names:
file_hash(os.path.join(directory, name), digest)
for file_path in file_paths:
file_hash(file_path, digest)


def zip_hash(
Expand Down

0 comments on commit 4a09cc5

Please sign in to comment.