mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-28 01:11:15 -03:00
De-duplicate install code in fish.rs
This commit is contained in:
committed by
Peter Ammon
parent
b69a1b2ffe
commit
db4c999272
@@ -137,50 +137,38 @@ fn install(confirm: bool, dir: PathBuf) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: These are duplicated, no idea how to extract
|
||||
// them into a function
|
||||
for file in Asset::iter() {
|
||||
let path = dir.join(file.as_ref());
|
||||
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
||||
eprintln!(
|
||||
"Creating directory '{}' failed",
|
||||
path.parent().unwrap().display()
|
||||
);
|
||||
return false;
|
||||
};
|
||||
let res = File::create(&path);
|
||||
let Ok(mut f) = res else {
|
||||
eprintln!("Creating file '{}' failed", path.display());
|
||||
continue;
|
||||
};
|
||||
// This should be impossible.
|
||||
let d = Asset::get(&file).expect("File was somehow not included???");
|
||||
if let Err(error) = f.write_all(&d.data) {
|
||||
eprintln!("error: {error}");
|
||||
return false;
|
||||
// This function can't be top-level because rust_embed is an optional dependency, so it can't
|
||||
// be a part of the function signature.
|
||||
fn extract_embed<T: rust_embed::Embed>(dir: &Path) -> bool {
|
||||
for file in T::iter() {
|
||||
let path = dir.join(file.as_ref());
|
||||
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
||||
eprintln!(
|
||||
"Creating directory '{}' failed",
|
||||
path.parent().unwrap().display()
|
||||
);
|
||||
return false;
|
||||
};
|
||||
let res = File::create(&path);
|
||||
let Ok(mut f) = res else {
|
||||
eprintln!("Creating file '{}' failed", path.display());
|
||||
continue;
|
||||
};
|
||||
// This should be impossible.
|
||||
let d = T::get(&file).expect("File was somehow not included???");
|
||||
if let Err(error) = f.write_all(&d.data) {
|
||||
eprintln!("error: {error}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for file in Docs::iter() {
|
||||
let path = dir.join(file.as_ref());
|
||||
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
||||
eprintln!(
|
||||
"Creating directory '{}' failed",
|
||||
path.parent().unwrap().display()
|
||||
);
|
||||
return false;
|
||||
};
|
||||
let res = File::create(&path);
|
||||
let Ok(mut f) = res else {
|
||||
eprintln!("Creating file '{}' failed", path.display());
|
||||
continue;
|
||||
};
|
||||
// This should be impossible.
|
||||
let d = Docs::get(&file).expect("File was somehow not included???");
|
||||
if let Err(error) = f.write_all(&d.data) {
|
||||
eprintln!("error: {error}");
|
||||
return false;
|
||||
}
|
||||
if !extract_embed::<Asset>(&dir) {
|
||||
return false;
|
||||
}
|
||||
if !extract_embed::<Docs>(&dir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let verfile = dir.join("fish-install-version");
|
||||
|
||||
Reference in New Issue
Block a user