Bug 1845017 - Disable the TestPHCExhaustion test r=glandium
[gecko.git] / tools / lint / file-perm / __init__.py
blobc5f31c008c73e9972cd81e3a818cd149931abd7a
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import os
6 import platform
8 from mozlint import result
9 from mozlint.pathutils import expand_exclusions
12 def lint(paths, config, fix=None, **lintargs):
13 results = []
14 fixed = 0
16 if platform.system() == "Windows":
17 # Windows doesn't have permissions in files
18 # Exit now
19 return {"results": results, "fixed": fixed}
21 files = list(expand_exclusions(paths, config, lintargs["root"]))
22 for f in files:
23 if os.access(f, os.X_OK):
24 if config.get("allow-shebang"):
25 with open(f, "r+") as content:
26 # Some source files have +x permissions
27 line = content.readline()
28 if line.startswith("#!"):
29 # Check if the file doesn't start with a shebang
30 # if it does, not a warning
31 continue
33 if fix:
34 # We want to fix it, do it and leave
35 os.chmod(f, 0o644)
36 fixed += 1
37 continue
39 res = {
40 "path": f,
41 "message": "Execution permissions on a source file",
42 "level": "error",
44 results.append(result.from_config(config, **res))
45 return {"results": results, "fixed": fixed}