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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Identification of the application runtime environment.
//!
//! This module detects whether the application is running as an isolated package (Flatpak, Snap)
//! or as a native system package (PPA, local DEB). This is
//! essential for correctly adjusting paths and permissions at runtime.
/**
* application_environment.rs
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use Path;
use process;
use env;
use cratesearch_string_file;
/// Defines the possible runtime environments for the application.
/// Retrieves the name of the current runtime environment as a string.
///
/// This function performs simple file system and environment variable checks
/// to distinguish between the most common sandbox formats.
///
/// # Return value
/// Returns "flatpak", "snap", or "native".
///
/// ```rust
/// let env_str = get_execution_environment();
/// println!("The app runs in the environment: **{}**", env_str);
/// ```
/// Analyzes the application's detailed installation source.
///
/// If the application runs natively, this function searches the APT source lists
/// to distinguish between a PPA source and a locally installed package.
///
/// # Arguments
/// * `search_string` - The identifier of the application in the sources lists (e.g., “fastboot-assistant”).
/// * `source_dir` - The directory of the APT lists (usually `/etc/apt/sources.list.d`).
///
/// # Return Value
/// Returns an instance of [AppEnvironment].
///
/// # Error Handling
/// If access to the system directories fails, an error message
/// is printed and the process terminates with status `1`, since the environment is critical
/// for the program's subsequent execution.
///
/// # Usage:
///
/// ```
/// fn main() {
/// const SEARCH_STRING: &str = "fastboot-assistant";
/// const SOURCES_DIR: &str = "/etc/apt/sources.list.d";
/// let current_env = check_application_environment(SEARCH_STRING, SOURCES_DIR);
/// match current_env {
/// AppEnvironment::Flatpak => println!("Action for Flatpak"),
/// AppEnvironment::Ppa => println!("Action for PPA"),
/// _ => println!("Other enviroment"),
/// }
/// }