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/// ```
19pub fn home() -> String {
20    var("HOME").unwrap_or_default()
21}
22
23/// Get the default path the macOS iMessage database is located at (macOS only)
24///
25/// # Example:
26///
27/// ```
28/// use imessage_database::util::dirs::default_db_path;
29///
30/// let path = default_db_path();
31/// println!("{path:?}");
32/// ```
33pub fn default_db_path() -> PathBuf {
34    PathBuf::from(format!("{}/{DEFAULT_PATH_MACOS}", home()))
35}