Compare file artifacts byte-for-byte, including modes and link targets.
(path)
| 41 | |
| 42 | |
| 43 | def files_under(path): |
| 44 | """Compare file artifacts byte-for-byte, including modes and link targets.""" |
| 45 | result = {} |
| 46 | if path.exists(): |
| 47 | for directory, dirs, files in os.walk(path, followlinks=False): |
| 48 | dirs[:] = [d for d in dirs if d not in ('.atomic', '.git')] |
| 49 | for name in files + [d for d in dirs if Path(directory, d).is_symlink()]: |
| 50 | p = Path(directory, name) |
| 51 | mode = p.lstat().st_mode |
| 52 | result[str(p.relative_to(path))] = ( |
| 53 | stat.S_IFMT(mode), stat.S_IMODE(mode), |
| 54 | os.readlink(p) if p.is_symlink() else hashlib.sha256(p.read_bytes()).hexdigest()) |
| 55 | dirs[:] = [d for d in dirs if not Path(directory, d).is_symlink()] |
| 56 | return result |