Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit 8749371

Browse files
committed
fix: locating runtime directory and config defaults
1 parent 0de2ed0 commit 8749371

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

Diff for: src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ async fn main() -> Result<(), CDEError> {
106106
};
107107
match conf_path.try_exists() {
108108
Ok(false) | Err(_) => {
109-
log::error!("Cannot find config at '{:?}'", conf_path);
109+
log::error!(
110+
"cannot find config at '{:?}'. creating directory and file...",
111+
conf_path
112+
);
110113
let _ = fs::create_dir(conf_path.parent().unwrap());
111-
let _ = fs::write(conf_path, "");
114+
let _ = fs::write(conf_path,"// Example config:\n/*\n(\n containers:\n [\n (\"fedora-toolbox-40\", Toolbox),\n (\"docker-container\", Docker),\n ],\n)\n*/",
115+
);
116+
log::info!(
117+
"write a configuration file. an example has been written to the config directory"
118+
)
112119
}
113120
_ => {}
114121
}

Diff for: src/server.rs

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
env,
33
fmt::Display,
4-
fs::{self, create_dir, read, read_to_string},
4+
fs::{self, read, read_to_string},
55
io,
66
path::{Path, PathBuf},
77
process::Command,
@@ -42,19 +42,23 @@ impl Display for ClientSetupError {
4242
}
4343

4444
pub async fn server(containers: ContainerList, owner: &str) -> Result<(), ClientSetupError> {
45-
let home = match env::var("RUNTIME_DIRECTORY") {
46-
Ok(h) => h,
47-
Err(_) => {
48-
log::error!("RUNTIME_DIRECTORY NOT FOUND. Make sure you're using the service!");
49-
panic!()
50-
}
51-
};
45+
let runtime_dir_str = env::var("RUNTIME_DIRECTORY").unwrap_or(format!(
46+
"/run/user/{}/container-desktop-entries/",
47+
env::var("UID").unwrap_or("1000".to_string())
48+
));
49+
let tmp_dir = Path::new(&runtime_dir_str);
50+
if !tmp_dir.exists() {
51+
log::warn!(
52+
"tmp_dir {} does not exist! creating directory...",
53+
tmp_dir.to_str().unwrap()
54+
);
55+
fs::create_dir(tmp_dir).unwrap();
56+
}
5257
let connection = Connection::session().await?;
5358
let proxy = DesktopEntryProxy::new(&connection).await?;
5459
if let Err(e) = proxy.remove_session_owner(&owner).await {
5560
log::error!("could not remove owner container-desktop-entries: {:?}", e);
5661
}
57-
let to_path = Path::new(&home).join(Path::new(".cache/container-desktop-entries/"));
5862
for (container_name, container_type) in containers.containers {
5963
if container_type.not_supported() {
6064
log::error!(
@@ -63,7 +67,7 @@ pub async fn server(containers: ContainerList, owner: &str) -> Result<(), Client
6367
);
6468
continue;
6569
}
66-
if let Err(kind) = set_up_client(&container_name, container_type, &to_path, owner).await {
70+
if let Err(kind) = set_up_client(&container_name, container_type, &tmp_dir, owner).await {
6771
log::error!("Error setting up client {}: {:?}", container_name, kind);
6872
}
6973
}
@@ -78,21 +82,6 @@ async fn set_up_client(
7882
) -> Result<(), ClientSetupError> {
7983
// Start client if client is not running
8084
start_client(container_name, container_type)?;
81-
if !to_path.exists() {
82-
log::warn!(
83-
"Runtime directory {} does not exist! Attempting to create directory manually...",
84-
to_path.to_str().unwrap()
85-
);
86-
match create_dir(to_path) {
87-
Ok(_) => {
88-
log::info!("App directory created!");
89-
}
90-
Err(e) => {
91-
log::error!("App directory could not be created. Reason: {}", e);
92-
panic!("App directory could not be created");
93-
}
94-
}
95-
}
9685
let _ = fs::create_dir(&to_path.join("applications"));
9786
let _ = fs::create_dir(&to_path.join("icons"));
9887
let _ = fs::create_dir(&to_path.join("pixmaps"));

0 commit comments

Comments
 (0)