Skip to content

Commit 5b911af

Browse files
committed
differentiate None and Some([]) for nvidia_gpus
1 parent 53c4d09 commit 5b911af

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

rust-app/src/config/handlers.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn get(path: web::Path<String>) -> impl Responder {
5252
let flake: String;
5353
let mut flake_lock: Option<String> = None;
5454
let mut network: Option<String> = None;
55-
let mut nvidia_gpus: Vec<u64> = vec![];
55+
let mut nvidia_gpus: Option<Vec<u64>> = None;
5656

5757
{
5858
let path = path.join("flake.nix");
@@ -89,10 +89,15 @@ async fn get(path: web::Path<String>) -> impl Responder {
8989
match read_to_string(&path) {
9090
Ok(file) => {
9191
if let Some(nspawn_flags) = between(&file, "\"", "\"") {
92+
if nspawn_flags.contains("nvidia") {
93+
nvidia_gpus = Some(vec![]);
94+
}
95+
9296
nspawn_flags.split(" ").for_each(|flag| {
9397
if flag.starts_with("--network-zone=") {
9498
network = Some(flag.replace("--network-zone=", ""));
9599
}
100+
96101
if flag.starts_with("--bind-ro=") {
97102
let path = flag.replace("--bind-ro=", "");
98103
if path.starts_with("/dev/nvidia") {
@@ -102,7 +107,7 @@ async fn get(path: web::Path<String>) -> impl Responder {
102107
{
103108
match device.parse::<u64>() {
104109
Ok(device_id) => {
105-
nvidia_gpus.push(device_id);
110+
nvidia_gpus.get_or_insert(vec![]).push(device_id);
106111
}
107112
Err(e) => {
108113
log::warn!(
@@ -132,11 +137,7 @@ async fn get(path: web::Path<String>) -> impl Responder {
132137
flake,
133138
flake_lock,
134139
network,
135-
nvidia_gpus: if nvidia_gpus.is_empty() {
136-
None
137-
} else {
138-
Some(nvidia_gpus)
139-
},
140+
nvidia_gpus,
140141
})
141142
}
142143

0 commit comments

Comments
 (0)