imessage_database/util/
dirs.rs

1/*!
2 Contains functions that generate the correct path to the default iMessage database location.
3*/
4
5use std::{env::var, path::PathBuf};
6
7use crate::tables::table::DEFAULT_PATH_MACOS;
8
9/// Get the user's home directory (macOS only)
10///
11/// # Example:
12///
13/// ```
14/// use imessage_database::util::dirs::home;
15///
16/// let path = home();
17/// println!("{path}");
18/// ```
19#[must_use]
20pub fn home() -> String {
21    var("HOME").unwrap_or_default()
22}
23
24/// Get the default path the macOS iMessage database is located at (macOS only)
25///
26/// # Example:
27///
28/// ```
29/// use imessage_database::util::dirs::default_db_path;
30///
31/// let path = default_db_path();
32/// println!("{path:?}");
33/// ```
34#[must_use]
35pub fn default_db_path() -> PathBuf {
36    PathBuf::from(format!("{}/{DEFAULT_PATH_MACOS}", home()))
37}