commit:     bd9c485781584e951e703ee191308db23506af9a
Author:     Siddhanth Rathod <xsiddhanthrathod <AT> gmail <DOT> com>
AuthorDate: Fri Jan 19 06:59:55 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jan 19 07:03:39 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=bd9c4857

eclean: handle when git3-src doesn't exist (port to Pathlib)

Followup to c584d83705a2ca08961e4f0b541442fdf9a75947.

Bug: https://bugs.gentoo.org/922455
Signed-off-by: Siddhanth Rathod <xsiddhanthrathod <AT> gmail.com>
Closes: https://github.com/gentoo/gentoolkit/pull/41
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/eclean/search.py | 50 ++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py
index 3610920..2eebcfd 100644
--- a/pym/gentoolkit/eclean/search.py
+++ b/pym/gentoolkit/eclean/search.py
@@ -5,12 +5,13 @@
 
 
 import os
+import shlex
 import stat
 import sys
-import shlex
 from functools import partial
 from inspect import signature
-from typing import Optional
+from pathlib import Path
+from typing import Optional, Set
 
 import portage
 from portage.dep import Atom, use_reduce
@@ -136,7 +137,7 @@ class DistfilesSearch:
         # gather the files to be cleaned
         self.output("...checking limits for %d ebuild sources" % len(pkgs))
 
-        vcs = self.vcs_check(_distdir)
+        vcs = self.vcs_check(Path(_distdir))
         checks = self._get_default_checks(size_limit, time_limit, exclude, 
destructive)
         checks.extend(extra_checks)
         clean_me = self._check_limits(_distdir, checks, clean_me)
@@ -335,31 +336,30 @@ class DistfilesSearch:
             deprecated.update(_deprecated)
         return pkgs, deprecated
 
-    def vcs_check(self, distdir):
+    def vcs_check(self, distdir: Path) -> Set:
         """Checks $DISTDIR/vcs-src for checkouts which are not in the vardb"""
         # For now we only check git
-        vcs_src = os.path.join(distdir, "git3-src")
-        if not os.path.exists(vcs_src):
-            return {}
-
+        vcs_src = distdir / "git3-src"
         expected_dirs = set()
-        for i in set(self.vardb.cpv_all()):
-            if "live" in self.vardb.aux_get(i, ["PROPERTIES"]):
-                try:
-                    # try to get the dir names of the cloned
-                    # repos from the environment file.
-                    vcs_dir = {
-                        i.split("=")[-1].strip('"')
-                        for i in shlex.split(
-                            self.vardb._aux_env_search(i, ["EVCS_STORE_DIRS"])[
-                                "EVCS_STORE_DIRS"
-                            ].strip("()")
-                        )
-                    }
-                    expected_dirs.update(vcs_dir)
-                except KeyError:
-                    pass
-        actual_dirs = {os.path.join(vcs_src, i) for i in os.listdir(vcs_src)}
+        actual_dirs = set()
+        if vcs_src.is_dir():
+            for i in set(self.vardb.cpv_all()):
+                if "live" in self.vardb.aux_get(i, ["PROPERTIES"]):
+                    try:
+                        # try to get the dir names of the cloned
+                        # repos from the environment file.
+                        vcs_dir = {
+                            i.split("=")[-1].strip('"')
+                            for i in shlex.split(
+                                self.vardb._aux_env_search(i, 
["EVCS_STORE_DIRS"])[
+                                    "EVCS_STORE_DIRS"
+                                ].strip("()")
+                            )
+                        }
+                        expected_dirs.update(vcs_dir)
+                    except KeyError:
+                        pass
+            actual_dirs = {str(i) for i in vcs_src.iterdir() if i.is_dir()}
         return actual_dirs.difference(expected_dirs)
 
     def _fetch_restricted(self, pkgs_, cpvs):

Reply via email to