Skip to content

Commit 4fd607b

Browse files
committed
Fix assemble from file and from url, resolve path in file row.
1 parent 40a216e commit 4fd607b

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

src/create_distrobox_dialog.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,35 @@ impl CreateDistroboxDialog {
349349

350350
let title = title.to_owned();
351351
let dialog_cb = clone!(
352+
#[weak(rename_to=this)]
353+
self,
354+
#[strong]
355+
title,
352356
#[weak]
353357
row,
354358
move |res: Result<File, _>| {
355359
if let Ok(file) = res {
356360
if let Some(path) = file.path() {
357-
row.set_subtitle(&path.display().to_string());
358-
cb(path);
361+
362+
glib::MainContext::ref_thread_default().spawn_local(async move {
363+
match this
364+
.root_store()
365+
.resolve_host_path(&path.display().to_string())
366+
.await
367+
{
368+
Ok(resolved_path) => {
369+
row.set_subtitle(&resolved_path);
370+
cb(PathBuf::from(resolved_path));
371+
}
372+
373+
Err(e) => {
374+
this.update_errors::<()>(&Err(Error::InvalidField(
375+
title.to_lowercase(),
376+
e.to_string(),
377+
)));
378+
}
379+
}
380+
});
359381
}
360382
}
361383
}
@@ -432,7 +454,9 @@ impl CreateDistroboxDialog {
432454
pub fn build_volumes_group(&self) -> adw::PreferencesGroup {
433455
let volumes_group = adw::PreferencesGroup::new();
434456
volumes_group.set_title("Volumes");
435-
volumes_group.set_description(Some("Specify volumes in the format 'host_path:container_path'"));
457+
volumes_group.set_description(Some(
458+
"Specify volumes in the format 'host_path:container_path'",
459+
));
436460

437461
let add_volume_button = adw::ButtonRow::builder().title("Add Volume").build();
438462
add_volume_button.connect_activated(clone!(

src/distrobox/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,26 @@ impl Distrobox {
717717

718718
// assemble
719719
pub fn assemble(&self, file_path: &str) -> Result<Box<dyn Child + Send>, Error> {
720+
if file_path.is_empty() {
721+
return Err(Error::InvalidField(
722+
"file_path".into(),
723+
"File path cannot be empty".into(),
724+
));
725+
}
720726
let mut cmd = dbcmd();
721-
cmd.arg("assemble").arg("--file").arg(file_path);
727+
cmd.arg("assemble").arg("create").arg("--file").arg(file_path);
722728
self.cmd_spawn(cmd)
723729
}
724730

725731
pub fn assemble_from_url(&self, url: &str) -> Result<Box<dyn Child + Send>, Error> {
732+
if url.is_empty() {
733+
return Err(Error::InvalidField(
734+
"url".into(),
735+
"URL cannot be empty".into(),
736+
));
737+
}
726738
let mut cmd = dbcmd();
727-
cmd.arg("assemble").arg("--file").arg(url);
739+
cmd.arg("assemble").arg("create").arg("--file").arg(url);
728740
self.cmd_spawn(cmd)
729741
}
730742
// create
@@ -1009,7 +1021,7 @@ Categories=Utility;Network;
10091021
db.assemble("/path/to/assemble.yml")?;
10101022
assert_eq!(
10111023
output_tracker.items()[0],
1012-
"\"distrobox\" [\"assemble\", \"--file\", \"/path/to/assemble.yml\"]"
1024+
"\"distrobox\" [\"assemble\", \"create\", \"--file\", \"/path/to/assemble.yml\"]"
10131025
);
10141026
Ok(())
10151027
}

src/store/root_store.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use gtk::prelude::*;
88
use gtk::{gio, glib};
99
use std::cell::RefCell;
1010
use std::default;
11-
use std::path::PathBuf;
11+
use std::path::Path;
1212
use std::rc::Rc;
1313
use std::time::Duration;
1414
use tracing::debug;
@@ -245,11 +245,17 @@ impl RootStore {
245245
}
246246
pub fn assemble_container(&self, file_path: &str) {
247247
let this = self.clone();
248-
let file_path = file_path.to_string();
249-
self.create_task("assemble", "assemble", move |task| async move {
250-
let child = this.distrobox().assemble(&file_path)?;
248+
let file_path_clone = file_path.to_string();
249+
let file_name = Path::new(file_path)
250+
.file_name()
251+
.and_then(|s| s.to_str())
252+
.unwrap_or(file_path);
253+
254+
let task = self.create_task(&file_name, "assemble", move |task| async move {
255+
let child = this.distrobox().assemble(&file_path_clone)?;
251256
task.handle_child_output(child).await
252257
});
258+
self.view_task(&task);
253259
}
254260
pub fn upgrade_all(&self) {
255261
for container in self.containers().snapshot() {

0 commit comments

Comments
 (0)