summaryrefslogtreecommitdiffhomepage
path: root/mullvad-paths/src/lib.rs
blob: 481cb06d3233346eee3de4bb99855b2b9bf37248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#![cfg(not(target_os = "android"))]

use std::io;

#[cfg(windows)]
pub mod windows;

#[cfg(windows)]
pub use windows::PRODUCT_NAME;

#[cfg(unix)]
mod unix;

#[cfg(unix)]
pub use unix::PRODUCT_NAME;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("Failed to create directory {0}")]
    CreateDirFailed(String, #[source] io::Error),

    #[error("Failed to remove directory {0}")]
    RemoveDir(String, #[source] io::Error),

    #[error("Failed to get directory permissions on {0}")]
    GetDirPermissionFailed(String, #[source] io::Error),

    #[error("Failed to set directory permissions on {0}")]
    SetDirPermissionFailed(String, #[source] io::Error),

    #[cfg(any(windows, target_os = "macos"))]
    #[error("Not able to find requested directory")]
    FindDirError,

    #[cfg(windows)]
    #[error("Missing %ALLUSERSPROFILE% environment variable")]
    NoProgramDataDir,

    #[cfg(windows)]
    #[error("Failed to create security attributes")]
    GetSecurityAttributes(#[source] io::Error),

    #[cfg(windows)]
    #[error(transparent)]
    ContainsNul(#[from] widestring::error::ContainsNul<u16>),

    #[error("Device data directory has not been set")]
    NoDataDir,
}

#[derive(Clone, Copy)]
pub struct UserPermissions {
    pub read: bool,
    pub write: bool,
    pub execute: bool,
}

impl UserPermissions {
    pub fn read_only() -> Self {
        UserPermissions {
            read: true,
            write: false,
            execute: false,
        }
    }
}

#[cfg(unix)]
use unix::create_dir;

#[cfg(windows)]
use windows::create_dir;

mod cache;
pub use crate::cache::{cache_dir, get_cache_dir, get_default_cache_dir};

mod logs;
pub use crate::logs::{get_default_log_dir, get_log_dir, log_dir};

pub mod resources;
pub use crate::resources::{get_default_resource_dir, get_resource_dir};

mod rpc_socket;
pub use crate::rpc_socket::{get_default_rpc_socket_path, get_rpc_socket_path};

mod settings;
pub use crate::settings::{get_default_settings_dir, settings_dir};