CrossSWE-Bench / scripts /restore_file_modes.py
Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
879 Bytes
"""Restore executable bits recorded in the release after HTTP snapshot download."""
from pathlib import Path
import argparse, json, os
ROOT = Path(__file__).resolve().parents[1]
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--check-only', action='store_true')
args = parser.parse_args()
mapping = json.loads((ROOT / 'data/file-modes.json').read_text())
changed = []
for name, mode in mapping.items():
path = ROOT / name
assert not Path(name).is_absolute() and '..' not in Path(name).parts and path.is_file() and not path.is_symlink()
if path.stat().st_mode & 0o777 != mode:
changed.append(name)
if not args.check_only:
path.chmod(mode)
print(json.dumps({'different_modes' if args.check_only else 'restored_modes':len(changed)}))