commit: e35bd03a3d6c3e12aa14890a667ac81674da0fb0 Author: Florian Schmaus <flow <AT> gentoo <DOT> org> AuthorDate: Sat Dec 20 13:14:29 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sat Dec 20 21:57:14 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e35bd03a
Add portage.util.path.get_fs_type() family of functions Signed-off-by: Florian Schmaus <flow <AT> gentoo.org> Part-of: https://github.com/gentoo/portage/pull/1532 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/util/path.py | 39 ++++++++++++++++++++++++++++++++++- lib/portage/util/portage_lru_cache.py | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/portage/util/path.py b/lib/portage/util/path.py index c906878a87..86902a6d6a 100644 --- a/lib/portage/util/path.py +++ b/lib/portage/util/path.py @@ -1,8 +1,12 @@ -# Copyright 2014-2021 Gentoo Authors +# Copyright 2014-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import errno +import os +import platform +from functools import lru_cache +from typing import Optional from portage import os @@ -50,3 +54,36 @@ def iter_parents(path): if not path: break yield path + + +@lru_cache(32) +def get_fs_type_cached(path: str) -> Optional[str]: + return get_fs_type(path) + + +def get_fs_type(path: str) -> Optional[str]: + if platform.system() == "Linux": + return get_fs_type_linux(path) + + return None + + +def get_fs_type_linux(path: str) -> Optional[str]: + real_path = os.path.realpath(path) + best_match_len = -1 + fs_type = None + + with open("/proc/mounts", "r") as f: + for line in f: + parts = line.split() + mount_point = parts[1] + + if not real_path.startswith(mount_point): + continue + + mount_point_len = len(mount_point) + if mount_point_len > best_match_len: + best_match_len = mount_point_len + fs_type = parts[2] + + return fs_type diff --git a/lib/portage/util/portage_lru_cache.py b/lib/portage/util/portage_lru_cache.py index 6cf689ef23..e1f179823c 100644 --- a/lib/portage/util/portage_lru_cache.py +++ b/lib/portage/util/portage_lru_cache.py @@ -15,6 +15,7 @@ def show_lru_cache_info(): portage.process._encoded_length: "encoded_length", portage.versions.catpkgsplit: "catpkgsplit", portage.versions.vercmp: "vercmp", + portate.util.path.get_fs_type_cached: "get_fs_type_cached", } print("Portage @lru_cache information")
