path: de-duplicate getter logic

Also remove comments which were already obsolete before these changes.

Closes #12365
This commit is contained in:
Daniel Rainer
2026-01-21 18:07:14 +01:00
committed by Johannes Altmanninger
parent 77471c500e
commit 28c0a8bc81

View File

@@ -18,32 +18,16 @@
/// Returns the user configuration directory for fish. If the directory or one of its parents
/// doesn't exist, they are first created.
///
/// \param path The directory as an out param
/// Return whether the directory was returned successfully
pub fn path_get_config() -> Option<WString> {
let dir = get_config_directory();
if dir.success() {
Some(dir.path.clone())
} else {
None
}
get_config_directory().path()
}
/// Returns the user data directory for fish. If the directory or one of its parents doesn't exist,
/// they are first created.
///
/// Volatile files presumed to be local to the machine, such as the fish_history will be stored in this directory.
///
/// \param path The directory as an out param
/// Return whether the directory was returned successfully
pub fn path_get_data() -> Option<WString> {
let dir = get_data_directory();
if dir.success() {
Some(dir.path.clone())
} else {
None
}
get_data_directory().path()
}
/// Returns the user cache directory for fish. If the directory or one of its parents doesn't exist,
@@ -51,16 +35,8 @@ pub fn path_get_data() -> Option<WString> {
///
/// Volatile files presumed to be local to the machine such as all the
/// generated_completions, will be stored in this directory.
///
/// \param path The directory as an out param
/// Return whether the directory was returned successfully
pub fn path_get_cache() -> Option<WString> {
let dir = get_cache_directory();
if dir.success() {
Some(dir.path.clone())
} else {
None
}
get_cache_directory().path()
}
#[derive(Clone, Copy, Eq, PartialEq)]
@@ -568,8 +544,8 @@ struct BaseDirectory {
}
impl BaseDirectory {
fn success(&self) -> bool {
self.err.is_none()
fn path(&self) -> Option<WString> {
self.err.is_none().then(|| self.path.clone())
}
}