aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2024-01-18 20:56:29 -0800
committerBrian Harring <ferringb@gmail.com>2024-01-23 11:57:59 -0800
commit63a901f8e5e58a6771b2435cf796ecc18369a622 (patch)
tree3d2a042e2ce93225d534db7529e329a2df9b6d72
parentCI/CD: only run doc deploy if its the main snakeoil repo. (diff)
downloadpkgcheck-63a901f8e5e58a6771b2435cf796ecc18369a622.tar.gz
pkgcheck-63a901f8e5e58a6771b2435cf796ecc18369a622.tar.bz2
pkgcheck-63a901f8e5e58a6771b2435cf796ecc18369a622.zip
feat: add check for a category is a file
This is beyond corner case, but if someone has a non directory in place of where a category is supposed to be, pkgcore and portage will silently suppress this. Pkgcore will be modified to emit a warning for this, but in the meantime, it's a cheap check, thus add it. Signed-off-by: Brian Harring <ferringb@gmail.com>
-rw-r--r--src/pkgcheck/checks/repo.py26
-rw-r--r--testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/expected.json1
-rwxr-xr-xtestdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/fix.sh2
-rw-r--r--testdata/repos/compatibility/CategoryIsNotDirectory0
-rw-r--r--testdata/repos/compatibility/profiles/categories1
5 files changed, 30 insertions, 0 deletions
diff --git a/src/pkgcheck/checks/repo.py b/src/pkgcheck/checks/repo.py
index eefc523e..1dcc99ad 100644
--- a/src/pkgcheck/checks/repo.py
+++ b/src/pkgcheck/checks/repo.py
@@ -1,4 +1,5 @@
import os
+import pathlib
from snakeoil.osutils import pjoin
@@ -89,3 +90,28 @@ class EmptyDirsCheck(GentooRepoCheck, RepoCheck):
for pkg in sorted(pkgs):
if not self.repo.versions[(cat, pkg)]:
yield EmptyPackageDir(pkg=RawCPV(cat, pkg, None))
+
+
+class CategoryIsNotDirectory(results.CategoryResult, results.Error):
+ """A category was found that exists but isn't a directory."""
+
+ scope = base.repo_scope
+
+ @property
+ def desc(self):
+ return f"category on disk exists and is not a directory: {self.category}"
+
+
+class RepositoryCategories(RepoCheck):
+ """Scan for fundamental category issues in the repository layout"""
+
+ _source = (sources.EmptySource, (base.repo_scope,))
+ known_results = frozenset({CategoryIsNotDirectory})
+
+ def finish(self):
+ repo = self.options.target_repo
+ repo_p = pathlib.Path(repo.location)
+ for category in repo.categories:
+ p = repo_p / category
+ if p.exists() and not p.is_dir():
+ yield CategoryIsNotDirectory(pkg=RawCPV(category, None, None))
diff --git a/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/expected.json b/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/expected.json
new file mode 100644
index 00000000..493a4a3b
--- /dev/null
+++ b/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/expected.json
@@ -0,0 +1 @@
+{"__class__": "CategoryIsNotDirectory", "category": "CategoryIsNotDirectory"}
diff --git a/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/fix.sh b/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/fix.sh
new file mode 100755
index 00000000..c37673b0
--- /dev/null
+++ b/testdata/data/repos/compatibility/RepositoryCategories/CategoryIsNotDirectory/fix.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+rm CategoryIsNotDirectory
diff --git a/testdata/repos/compatibility/CategoryIsNotDirectory b/testdata/repos/compatibility/CategoryIsNotDirectory
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/testdata/repos/compatibility/CategoryIsNotDirectory
diff --git a/testdata/repos/compatibility/profiles/categories b/testdata/repos/compatibility/profiles/categories
new file mode 100644
index 00000000..5578f02c
--- /dev/null
+++ b/testdata/repos/compatibility/profiles/categories
@@ -0,0 +1 @@
+CategoryIsNotDirectory