commit: 63a901f8e5e58a6771b2435cf796ecc18369a622
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Fri Jan 19 04:56:29 2024 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 23 19:57:59 2024 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=63a901f8
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 <AT> gmail.com>
src/pkgcheck/checks/repo.py | 26 ++++++++++++++++++++++
.../CategoryIsNotDirectory/expected.json | 1 +
.../CategoryIsNotDirectory/fix.sh | 2 ++
.../repos/compatibility/CategoryIsNotDirectory | 0
testdata/repos/compatibility/profiles/categories | 1 +
5 files changed, 30 insertions(+)
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
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