File size: 879 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""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)}))