From b546bb9bf23a3fbac786b6d2d840a0624fd212a9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 29 Jun 2026 14:51:32 +1000 Subject: [PATCH] Fix import of stat_triplet --- enroll/harvest_collectors/paths.py | 12 ++++++++---- tests/test_harvest.py | 7 +++++-- tests/test_harvest_collectors.py | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/enroll/harvest_collectors/paths.py b/enroll/harvest_collectors/paths.py index 15c2884..e59d9b0 100644 --- a/enroll/harvest_collectors/paths.py +++ b/enroll/harvest_collectors/paths.py @@ -4,7 +4,6 @@ import glob import os from typing import Dict, List, Optional, Set -from .. import harvest as h from ..capture import capture_file, capture_link from ..harvest_types import ( ExcludedFile, @@ -16,7 +15,12 @@ from ..harvest_types import ( ) from ..system_paths import MAX_FILES_CAP from ..pathfilter import expand_includes -from ..fsutil import is_dir_no_symlink_components, path_has_symlink_component +from ..fsutil import ( + is_dir_no_symlink_components, + path_has_symlink_component, + stat_dir_triplet, + stat_triplet, +) from .context import HarvestCollector, HarvestContext @@ -78,7 +82,7 @@ class UsrLocalCustomCollector(HarvestCollector): if not os.path.isfile(path) or os.path.islink(path): continue try: - owner, group, mode = h.stat_triplet(path) + owner, group, mode = stat_triplet(path) except OSError: self.excluded.append(ExcludedFile(path=path, reason="unreadable")) continue @@ -254,7 +258,7 @@ class ExtraPathsCollector(HarvestCollector): deny = None if not deny: try: - owner, group, mode = h.stat_dir_triplet(dirpath) + owner, group, mode = stat_dir_triplet(dirpath) self.managed_dirs.append( ManagedDir( path=dirpath, diff --git a/tests/test_harvest.py b/tests/test_harvest.py index 0568b22..27bf4a1 100644 --- a/tests/test_harvest.py +++ b/tests/test_harvest.py @@ -10,6 +10,7 @@ from enroll.platform import PlatformInfo from enroll.systemd import UnitInfo from enroll.pathfilter import PathFilter import enroll.capture as capture +from enroll.harvest_collectors import paths as path_collectors from enroll.capture import ( capture_file as _capture_file, capture_link as _capture_link, @@ -255,7 +256,7 @@ def test_harvest_dedup_manual_packages_and_builds_etc_custom( # /usr/local/bin/readme.txt remains non-executable return ("root", "root", "0644") - monkeypatch.setattr(harvest, "stat_triplet", fake_stat_triplet) + monkeypatch.setattr(path_collectors, "stat_triplet", fake_stat_triplet) monkeypatch.setattr(harvest, "stat_dir_triplet", fake_stat_triplet) monkeypatch.setattr(capture, "stat_triplet", fake_stat_triplet) @@ -400,7 +401,9 @@ def test_shared_cron_snippet_prefers_matching_role_over_lexicographic( ) monkeypatch.setattr(harvest, "get_backend", lambda info=None: backend) - monkeypatch.setattr(harvest, "stat_triplet", lambda p: ("root", "root", "0644")) + monkeypatch.setattr( + path_collectors, "stat_triplet", lambda p: ("root", "root", "0644") + ) monkeypatch.setattr(harvest, "stat_dir_triplet", lambda p: ("root", "root", "0755")) monkeypatch.setattr(capture, "stat_triplet", lambda p: ("root", "root", "0644")) monkeypatch.setattr(harvest, "collect_non_system_users", lambda: []) diff --git a/tests/test_harvest_collectors.py b/tests/test_harvest_collectors.py index 73752f5..3c336b6 100644 --- a/tests/test_harvest_collectors.py +++ b/tests/test_harvest_collectors.py @@ -285,7 +285,7 @@ def test_extra_paths_collector_records_dirs_files_notes_and_excludes( ) return True - monkeypatch.setattr(paths.h, "stat_dir_triplet", fake_stat_triplet) + monkeypatch.setattr(paths, "stat_dir_triplet", fake_stat_triplet) monkeypatch.setattr(paths, "capture_file", lambda *a, **kw: fake_capture_file(**kw)) ctx = _context( @@ -321,7 +321,7 @@ def test_extra_paths_collector_skips_already_captured_files(monkeypatch, tmp_pat file_path.write_text("ok", encoding="utf-8") calls: list[str] = [] - monkeypatch.setattr(paths.h, "stat_dir_triplet", lambda p: ("root", "root", "0755")) + monkeypatch.setattr(paths, "stat_dir_triplet", lambda p: ("root", "root", "0755")) monkeypatch.setattr( paths, "capture_file", lambda *a, **kw: calls.append(kw["abs_path"]) or True ) @@ -383,7 +383,7 @@ def test_usr_local_custom_collector_scans_executable_bin_and_notes_cap( monkeypatch.setattr(paths.os, "walk", fake_walk) monkeypatch.setattr(paths.os.path, "isfile", fake_isfile) monkeypatch.setattr(paths.os.path, "islink", lambda p: False) - monkeypatch.setattr(paths.h, "stat_triplet", fake_stat_triplet) + monkeypatch.setattr(paths, "stat_triplet", fake_stat_triplet) monkeypatch.setattr(paths, "capture_file", lambda *a, **kw: fake_capture_file(**kw)) ctx = _context(tmp_path)