Skip to main content

atuin_common/path/
mod.rs

1//! Filesystem path utilities and extension traits.
2
3pub mod display_rich;
4
5use std::path::{Path, PathBuf};
6
7pub use display_rich::{DisplayRichExt, RichDisplay};
8
9/// Utility extensions for paths in atuin.
10pub trait PathExt {
11    /// Check whether the given path is a symlink, and a dangling one at that.
12    fn is_dangling_symlink(&self) -> bool;
13}
14
15impl<P: AsRef<Path>> PathExt for P {
16    fn is_dangling_symlink(&self) -> bool {
17        let path: &Path = self.as_ref();
18        path.is_symlink() && !path.exists()
19    }
20}
21
22/// An owned path that is dependent on environment variables.
23///
24/// This type is used as part of a workaround to handle the case where the daemon may have been
25/// spawned in an environment with `$TMPDIR` unset, but where `$TMPDIR` *is* set when the client is
26/// run. This type contains *both* paths the client needs to try to connect to.
27pub struct EnvDependentPathBuf {
28    /// The primary form of the path.
29    ///
30    /// For example, `$TMPDIR/example.txt`.
31    pub primary: PathBuf,
32
33    /// The path that would be used if none of the relevant environment variables were set.
34    ///
35    /// For example, `/tmp/example.txt` even when `$TMPDIR` is set.
36    pub envless: Option<PathBuf>,
37}