summaryrefslogtreecommitdiffstats
path: root/tools/lint/file-perm/__init__.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /tools/lint/file-perm/__init__.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/file-perm/__init__.py')
-rw-r--r--tools/lint/file-perm/__init__.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/lint/file-perm/__init__.py b/tools/lint/file-perm/__init__.py
new file mode 100644
index 0000000000..c5f31c008c
--- /dev/null
+++ b/tools/lint/file-perm/__init__.py
@@ -0,0 +1,45 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import platform
+
+from mozlint import result
+from mozlint.pathutils import expand_exclusions
+
+
+def lint(paths, config, fix=None, **lintargs):
+ results = []
+ fixed = 0
+
+ if platform.system() == "Windows":
+ # Windows doesn't have permissions in files
+ # Exit now
+ return {"results": results, "fixed": fixed}
+
+ files = list(expand_exclusions(paths, config, lintargs["root"]))
+ for f in files:
+ if os.access(f, os.X_OK):
+ if config.get("allow-shebang"):
+ with open(f, "r+") as content:
+ # Some source files have +x permissions
+ line = content.readline()
+ if line.startswith("#!"):
+ # Check if the file doesn't start with a shebang
+ # if it does, not a warning
+ continue
+
+ if fix:
+ # We want to fix it, do it and leave
+ os.chmod(f, 0o644)
+ fixed += 1
+ continue
+
+ res = {
+ "path": f,
+ "message": "Execution permissions on a source file",
+ "level": "error",
+ }
+ results.append(result.from_config(config, **res))
+ return {"results": results, "fixed": fixed}