"""Read file metadata using both providers on a private synthetic file.""" import json import os from pathlib import Path import platform import sys import tempfile import time FIELDS = ('st_dev', 'st_ino', 'st_size', 'st_mtime_ns', 'st_ctime_ns', 'st_birthtime_ns') def values(info): return {name: getattr(info, name, None) for name in FIELDS} with tempfile.TemporaryDirectory(prefix='wecom-stat-compat-') as directory: path = Path(directory) / 'synthetic-client.exe' path.write_bytes(b'file metadata compatibility, not an executable\x00') time.sleep(0.02) os.utime(path, ns=(946684800000000000, 946684800000000000)) path_first = values(path.stat()) with path.open('rb') as handle: fd_first = values(os.fstat(handle.fileno())) content = handle.read() fd_after = values(os.fstat(handle.fileno())) with path.open('rb') as reopened: fd_reopened = values(os.fstat(reopened.fileno())) path_after = values(path.stat()) report = { 'python': sys.version, 'executable': sys.executable, 'platform': platform.platform(), 'pathStat': path_first, 'fdStat': fd_first, 'crossProviderDifferences': [name for name in FIELDS if path_first[name] != fd_first[name]], 'pathProviderStable': path_first == path_after, 'fdProviderStable': fd_first == fd_after == fd_reopened, 'bytesRead': len(content), 'scope': 'private temporary synthetic file; no client process access', } print(json.dumps(report, ensure_ascii=False, indent=2))