Skip to content

Commit ef07658

Browse files
committed
update deps, clean up some code
1 parent b3c89c0 commit ef07658

18 files changed

Lines changed: 128 additions & 154 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ utoipa-axum = "0.2.0"
1717
reqwest = { version = "0.13.0", features = ["hickory-dns", "json", "multipart", "stream"] }
1818
tokio = { version = "1.43.0", features = ["full"] }
1919
chrono = { version = "0.4.40", features = ["serde"] }
20-
futures-util = "0.3.31"
2120
tokio-util = { version = "0.7.15", features = ["full"] }
2221
uuid = { version = "1.16.0", features = ["serde", "v4"] }
2322
rand = "0.9.1"

application/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77
[dependencies]
88
unrar = { path = "../unrar-rs" }
99
tracing = "0.1.41"
10-
tracing-subscriber = { version = "=0.3.19", features = ["chrono"] } # temporary pin to avoid new ansi escaping
10+
tracing-subscriber = { version = "0.3.19", features = ["chrono"] }
1111
tracing-appender = "0.2.3"
1212
anyhow = { workspace = true }
1313
axum = { workspace = true }
@@ -20,13 +20,12 @@ utoipa = { workspace = true }
2020
utoipa-axum = { workspace = true }
2121
reqwest = { workspace = true }
2222
tokio = { workspace = true }
23-
colored = "3.0.0"
2423
chrono = { workspace = true }
24+
colored = "3.0.0"
2525
nestify = "0.3.3"
2626
rayon = "1.10.0"
2727
serde_norway = "0.9.42"
2828
serde_default = "0.2.0"
29-
futures-util = { workspace = true }
3029
tokio-util = { workspace = true }
3130
uuid = { workspace = true }
3231
rand = { workspace = true }
@@ -89,9 +88,6 @@ sntpc = { version = "0.8.1", features = ["std"] }
8988
libz-ng-sys = "=1.1.23" # temporary pin due to riscv64 issues
9089
notify = "8.2.0"
9190

92-
[target.'cfg(unix)'.dependencies]
93-
users = "0.11.0"
94-
9591
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
9692
tikv-jemallocator = "0.6.0"
9793

application/src/config.rs

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,25 +1204,43 @@ impl Config {
12041204
return Ok(());
12051205
}
12061206

1207-
if self.system.user.rootless.enabled {
1208-
let user = users::get_current_uid();
1209-
let group = users::get_current_gid();
1210-
1211-
if let Some(username) = users::get_current_username() {
1212-
self.system.username = username.to_string_lossy().to_compact_string();
1213-
}
1207+
if let Ok(current_pid) = sysinfo::get_current_pid() {
1208+
let mut sys = sysinfo::System::new_all();
1209+
sys.refresh_processes_specifics(
1210+
sysinfo::ProcessesToUpdate::Some(&[current_pid]),
1211+
false,
1212+
sysinfo::ProcessRefreshKind::nothing().with_memory(),
1213+
);
1214+
if let Some(process) = sys.process(current_pid) {
1215+
if self.system.user.rootless.enabled {
1216+
if let Some(user) = process.user_id() {
1217+
let users = sysinfo::Users::new_with_refreshed_list();
1218+
if let Some(user) = users.get_user_by_id(user) {
1219+
self.system.username = user.name().to_compact_string();
1220+
}
12141221

1215-
self.system.user.uid = user;
1216-
self.system.user.gid = group;
1222+
self.system.user.uid = **user;
1223+
}
1224+
if let Some(group) = process.group_id() {
1225+
self.system.user.gid = *group;
1226+
}
12171227

1218-
return Ok(());
1219-
}
1228+
return Ok(());
1229+
}
12201230

1221-
if let Some(user) = users::get_user_by_name(&self.system.username) {
1222-
self.system.user.uid = user.uid();
1223-
self.system.user.gid = user.primary_group_id();
1231+
let mut found_user = false;
1232+
if let Some(user) = process.user_id() {
1233+
self.system.user.uid = **user;
1234+
found_user = true;
1235+
}
1236+
if let Some(group) = process.group_id() {
1237+
self.system.user.gid = *group;
1238+
}
12241239

1225-
return Ok(());
1240+
if found_user {
1241+
return Ok(());
1242+
}
1243+
}
12261244
}
12271245

12281246
let command = if release.contains("alpine") {
@@ -1258,11 +1276,21 @@ impl Config {
12581276
);
12591277
}
12601278

1261-
let user = users::get_user_by_name(&self.system.username)
1262-
.context(format!("failed to get user {}", self.system.username))?;
1279+
let users = sysinfo::Users::new_with_refreshed_list();
1280+
1281+
let Some(user) = users
1282+
.list()
1283+
.iter()
1284+
.find(|u| u.name() == self.system.username)
1285+
else {
1286+
return Err(anyhow::anyhow!(
1287+
"failed to find user {} after creating it",
1288+
self.system.username
1289+
));
1290+
};
12631291

1264-
self.system.user.uid = user.uid();
1265-
self.system.user.gid = user.primary_group_id();
1292+
self.system.user.uid = **user.id();
1293+
self.system.user.gid = *user.group_id();
12661294

12671295
Ok(())
12681296
}

application/src/main.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
1919

2020
async fn handle_request(req: Request<Body>, next: Next) -> Result<Response<Body>, StatusCode> {
2121
tracing::info!(
22-
"http {} {}{}",
22+
path = req.uri().path(),
23+
query = req.uri().query().unwrap_or_default(),
24+
"http {}",
2325
req.method().to_string().to_lowercase(),
24-
req.uri().path().cyan(),
25-
if let Some(query) = req.uri().query() {
26-
format!("?{query}")
27-
} else {
28-
"".to_string()
29-
}
30-
.bright_cyan()
3126
);
3227

3328
Ok(wings_rs::response::ACCEPT_HEADER
@@ -156,11 +151,8 @@ async fn main() {
156151
tracing::info!(" \\_/\\_/ |_|_| |_|\\__, |___/__ ___ ");
157152
tracing::info!(" __/ | | '__/ __|");
158153
tracing::info!(" |___/ | | \\__ \\");
159-
tracing::info!(
160-
"{: >25} |_| |___/",
161-
format!("{} (git-{})", wings_rs::VERSION, wings_rs::GIT_COMMIT)
162-
);
163-
tracing::info!("github.com/calagopus/wings\n");
154+
tracing::info!("{: >25} |_| |___/", wings_rs::VERSION);
155+
tracing::info!("github.com/calagopus/wings#{}\n", wings_rs::GIT_COMMIT);
164156
}
165157
}
166158

@@ -465,15 +457,10 @@ async fn main() {
465457
));
466458

467459
tracing::info!(
468-
"{} listening on {} {}",
469-
"ssh server".yellow(),
460+
"ssh server listening on {} (app@{}, {}ms)",
470461
address.to_string().cyan(),
471-
format!(
472-
"(app@{}, {}ms)",
473-
wings_rs::VERSION,
474-
state.start_time.elapsed().as_millis()
475-
)
476-
.bright_black()
462+
wings_rs::VERSION,
463+
state.start_time.elapsed().as_millis()
477464
);
478465

479466
match server.run_on_address(Arc::new(config), address).await {
@@ -516,11 +503,7 @@ async fn main() {
516503
.context("failed to load SSL certificate and key")
517504
.unwrap();
518505

519-
tracing::info!(
520-
"{} listening on {}",
521-
"https server".bright_red(),
522-
address.to_string().cyan(),
523-
);
506+
tracing::info!("https listening on {}", address.to_string().cyan(),);
524507

525508
match axum_server::bind_rustls(address, config)
526509
.serve(router.into_make_service_with_connect_info::<SocketAddr>())
@@ -538,11 +521,7 @@ async fn main() {
538521
}
539522
}
540523
} else {
541-
tracing::info!(
542-
"{} listening on {}",
543-
"http server".bright_red(),
544-
address.to_string().cyan(),
545-
);
524+
tracing::info!("http listening on {}", address.to_string().cyan(),);
546525

547526
match axum::serve(
548527
match tokio::net::TcpListener::bind(address).await {
@@ -578,11 +557,7 @@ async fn main() {
578557
{
579558
let socket_path = &state.config.api.host;
580559

581-
tracing::info!(
582-
"{} listening on {}",
583-
"http server".bright_red(),
584-
socket_path.cyan(),
585-
);
560+
tracing::info!("http server listening on {}", socket_path.cyan(),);
586561

587562
let router = router.layer(axum::middleware::from_fn(
588563
|mut req: Request, next: Next| async move {

application/src/routes/api/servers/_server_/files/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod post {
1313
extract::Query,
1414
http::{HeaderMap, StatusCode},
1515
};
16-
use futures_util::StreamExt;
16+
use futures::StreamExt;
1717
use serde::{Deserialize, Serialize};
1818
use tokio::io::AsyncWriteExt;
1919
use utoipa::ToSchema;

application/src/routes/api/system/stats/ws.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub async fn handle_ws(ws: WebSocketUpgrade, state: GetState) -> Response {
1313
ws.on_upgrade(move |socket| async move {
1414
let socket = Arc::new(tokio::sync::Mutex::new(socket));
1515

16-
type ReturnType = dyn futures_util::Future<Output = Result<(), anyhow::Error>> + Send;
16+
type ReturnType = dyn Future<Output = Result<(), anyhow::Error>> + Send;
1717
let futures: [Pin<Box<ReturnType>>; 2] = [
1818
// Stats Listener
1919
Box::pin({
@@ -50,7 +50,7 @@ pub async fn handle_ws(ws: WebSocketUpgrade, state: GetState) -> Response {
5050
}),
5151
];
5252

53-
if let Err(err) = futures_util::future::try_join_all(futures).await {
53+
if let Err(err) = futures::future::try_join_all(futures).await {
5454
tracing::debug!("error while serving stats websocket: {:?}", err);
5555
}
5656
})

0 commit comments

Comments
 (0)