Skip to content

Commit

Permalink
Merge pull request #66 from AaronBurchfield/munki_pkginfo_installer_case
Browse files Browse the repository at this point in the history
Adds a check for missing installer items in pkginfo files
  • Loading branch information
homebysix authored Nov 18, 2023
2 parents 6f814f5 + 02644cd commit 6517fe1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pre_commit_hooks/check_munki_pkgsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import os
import plistlib
from pathlib import Path
from xml.parsers.expat import ExpatError

from pre_commit_hooks.util import (
Expand Down Expand Up @@ -37,6 +38,22 @@ def build_argument_parser():
return parser


def _check_case_sensitive_path(path):
# Return immediately if the file does not exist
if not os.path.exists(path):
return False

p = Path(path)
while True:
# At root, p == p.parent --> break loop and return True
if p == p.parent:
return True
# If string representation of path is not in parent directory, return False
if str(p) not in map(str, p.parent.iterdir()):
return False
p = p.parent


def main(argv=None):
"""Main process."""

Expand Down Expand Up @@ -114,6 +131,22 @@ def main(argv=None):
)
retval = 1

# Check for missing installer items
if all(
(
"installer_item_location" in pkginfo,
not _check_case_sensitive_path(
os.path.join("pkgs", pkginfo.get("installer_item_location"))
),
)
):
print(
"{}: installer item does not exist or path is not case sensitive".format(
filename
)
)
retval = 1

# Check for pkg filenames showing signs of duplicate imports.
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
print(
Expand Down

0 comments on commit 6517fe1

Please sign in to comment.