Skip to content

Commit

Permalink
feat(backend/custom): wip on making this actually work?
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Jan 23, 2025
1 parent cfd287a commit 7624219
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 51 deletions.
57 changes: 17 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ serde_with = "3.9.0"
uuid = { version = "1.10.0", features = ["serde"] }
tiffin = { version = "0.3.2" }
tracing-journald = "0.3.0"
rayon = "1.10.0"
# rayon = "1.10.0"
process_alive = "0.1.1"
crossbeam-queue = "0.3.11"
strip-ansi-escapes = "0.2.0"
Expand All @@ -52,6 +52,7 @@ format-bytes = "0.3.0"
ipc-channel = { version = "0.19.0", features = ["async"] }
which = "7.0.1"
freedesktop-desktop-entry = "0.7.7"
fs-more = "0.8.0"

[dependencies.os-detect]
git = "https://github.com/FyraLabs/distinst"
Expand Down
29 changes: 26 additions & 3 deletions src/backend/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@ use std::path::Component;
use std::path::Path;
use std::path::PathBuf;

use color_eyre::eyre::Context;

use super::install::InstallationState;

const DIR_COPY_OPTS: fs_more::directory::DirectoryCopyOptions = {
use fs_more::directory::{
BrokenSymlinkBehaviour, CollidingSubDirectoryBehaviour, DestinationDirectoryRule,
DirectoryCopyDepthLimit, DirectoryCopyOptions, SymlinkBehaviour,
};
use fs_more::file::CollidingFileBehaviour;
DirectoryCopyOptions {
destination_directory_rule: DestinationDirectoryRule::AllowNonEmpty {
colliding_file_behaviour: CollidingFileBehaviour::Overwrite,
colliding_subdirectory_behaviour: CollidingSubDirectoryBehaviour::Continue,
},
copy_depth_limit: DirectoryCopyDepthLimit::Unlimited,
symlink_behaviour: SymlinkBehaviour::Keep,
broken_symlink_behaviour: BrokenSymlinkBehaviour::Keep,
}
};

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct MountTarget {
#[doc(hidden)]
Expand Down Expand Up @@ -100,11 +119,15 @@ pub fn install_custom(

let copy_source = PathBuf::from(InstallationState::determine_copy_source());
if copy_source.is_file() {
// TODO: impl callback status progress
super::mksys::unsquash_copy(&copy_source, destroot, |_, _| {})?;
crate::stage!("Extracting files" {
super::mksys::unsquash_copy(&copy_source, destroot, |_, _| {})?;
});
} else {
crate::stage!("Copying files" {
fs_more::directory::copy_directory(&copy_source, destroot, DIR_COPY_OPTS).wrap_err("can't copy files")?;
});
tracing::info!(?copy_source, ?destroot, "Copying directory");
crate::util::fs::copy_dir(&copy_source, destroot)?;
// crate::util::fs::copy_dir(&copy_source, destroot)?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ impl SimpleComponent for AppModel {
Page::Welcome => *model.welcome_page.widget(),
Page::Destination => *model.destination_page.widget(),
Page::InstallationType => *model.installation_type_page.widget(),
Page::Confirmation => *model.confirmation_page.widget(),
Page::Installation => *model.installation_page.widget(),
Page::InstallDual => *model.install_dual_page.widget(),
Page::InstallCustom => *model.install_custom_page.widget(),
Page::Confirmation => *model.confirmation_page.widget(),
Page::Installation => *model.installation_page.widget(),
Page::Completed => *model.completed_page.widget(),
Page::Failure => *model.failure_page.widget(),
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::backend::install::InstallationMessage;
use crate::prelude::*;
use crate::{NavigationAction, INSTALLATION_STATE};
use color_eyre::Result;
use relm4::tokio::sync::broadcast::Receiver;
use relm4::{Component, ComponentParts, ComponentSender};
use std::time::Duration;

Expand Down
6 changes: 4 additions & 2 deletions src/pages/installcustom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl SimpleComponent for AddDialog {
// HACK: relm4 doesn't perform the #[watch] until the UI is updated by the user
// e.g. they typed something into the entry, then relm4 actually finally realize
// it needs to set this as sensitive
//
//
// therefore right here we just have relm4 default to a sensitivity before any UI trigs
set_sensitive: !model.partition.is_empty(),
},
Expand Down Expand Up @@ -721,7 +721,9 @@ impl AddDialog {
// WARN: by design yes this is a memleak but we have no choice
ctrl.detach_runtime();
ctrl.widget().set_transient_for(root_window.as_ref());
libhelium::prelude::WindowExt::set_parent(ctrl.widget(), root_window.as_ref());
libhelium::prelude::WindowExt::set_parent(ctrl.widget(), root_window.as_ref()); // FIXME: doubt if this actually works
// temporary hack is to use the gtk one instead
gtk::prelude::WidgetExt::set_parent(ctrl.widget(), &root_window.expect("no root window"));
ctrl.widget().present();
ctrl
}
Expand Down
30 changes: 29 additions & 1 deletion src/util/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ pub fn exist_then_read_dir<A: AsRef<Path>>(
}
}

/*
pub fn copy_dir<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> color_eyre::Result<()> {
use rayon::iter::{ParallelBridge, ParallelIterator};
// todo: use walkdir or something
// or https://crates.io/crates/dircpy
// or https://docs.rs/fs-more/latest/fs_more/directory/fn.copy_directory.html
//
// also parallelizing this is a bit of a waste, since we're doing a lot of IO,
// and we might mess with the dir order
let to = to.as_ref();
std::fs::create_dir_all(to)?;
Expand All @@ -47,7 +55,26 @@ pub fn copy_dir<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> color_eyre::R
if metadata.is_dir() {
copy_dir(dir_entry.path(), to)?;
} else if metadata.is_symlink() {
let link = std::fs::read_link(dir_entry.path())?;
if dir_entry.path().exists() {
tracing::warn!(
?dir_entry,
"File seems to already exist.. Removing anyway to make way for symlink"
);
std::fs::remove_file(dir_entry.path()).map_err(|e| {
eyre!("can't remove file for symlink")
.note(format!("From : {}", dir_entry.path().display()))
.note(format!("To : {}", to.display()))
// .note(format!("Link : {}", link.display()))
.wrap_err(e)
})?;
}
let link = match std::fs::read_link(dir_entry.path()) {
Ok(link) => link,
Err(e) => {
tracing::warn!(path=?dir_entry.path(), ?e, "link does not exist, skipping");
return Ok(());
}
};
std::os::unix::fs::symlink(&link, &to).map_err(|e| {
eyre!("can't symlink")
.note(format!("From : {}", dir_entry.path().display()))
Expand All @@ -66,6 +93,7 @@ pub fn copy_dir<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> color_eyre::R
Ok(())
})
}
*/

/// Get partition number from partition path
///
Expand Down
3 changes: 2 additions & 1 deletion src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ macro_rules! stage {
let sender = m.lock().unwrap();
// Then we are in a non-interactive install, which means we export IPC
// to stdout
let status_localized = gettextrs::gettext($s).to_owned();
let install_status =
$crate::backend::install::InstallationMessage::Status($s.to_owned());
$crate::backend::install::InstallationMessage::Status(status_localized);
sender.send(install_status).unwrap();
}

Expand Down

0 comments on commit 7624219

Please sign in to comment.