Skip to content

Commit 02644cd

Browse files
check that installer items exist and match the file system case
1 parent 624a708 commit 02644cd

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

pre_commit_hooks/check_munki_pkgsinfo.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import os
77
import plistlib
8+
from pathlib import Path
89
from xml.parsers.expat import ExpatError
910

1011
from pre_commit_hooks.util import (
@@ -37,6 +38,22 @@ def build_argument_parser():
3738
return parser
3839

3940

41+
def _check_case_sensitive_path(path):
42+
# Return immediately if the file does not exist
43+
if not os.path.exists(path):
44+
return False
45+
46+
p = Path(path)
47+
while True:
48+
# At root, p == p.parent --> break loop and return True
49+
if p == p.parent:
50+
return True
51+
# If string representation of path is not in parent directory, return False
52+
if str(p) not in map(str, p.parent.iterdir()):
53+
return False
54+
p = p.parent
55+
56+
4057
def main(argv=None):
4158
"""Main process."""
4259

@@ -114,6 +131,22 @@ def main(argv=None):
114131
)
115132
retval = 1
116133

134+
# Check for missing installer items
135+
if all(
136+
(
137+
"installer_item_location" in pkginfo,
138+
not _check_case_sensitive_path(
139+
os.path.join("pkgs", pkginfo.get("installer_item_location"))
140+
),
141+
)
142+
):
143+
print(
144+
"{}: installer item does not exist or path is not case sensitive".format(
145+
filename
146+
)
147+
)
148+
retval = 1
149+
117150
# Check for pkg filenames showing signs of duplicate imports.
118151
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
119152
print(

0 commit comments

Comments
 (0)