Skip to content

Commit 047d2b6

Browse files
authored
fix: use std::fs wherever possible
1 parent 8923830 commit 047d2b6

5 files changed

Lines changed: 33 additions & 20 deletions

File tree

src/installers/linux.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{shell_command};
1+
use std::fs::{copy, metadata, remove_file, create_dir};
2+
use crate::shell_command;
23
use regex::Regex;
34

45
pub fn install_l() {
@@ -23,12 +24,20 @@ pub fn install_l() {
2324

2425
println!("Unpacking release...");
2526

26-
shell_command("tar", vec!["-xf", "oxido*.tar.gz"]);
27+
shell_command("tar", vec!["-xf", "oxido-linux.tar.gz"]);
2728

2829
println!("Moving to $HOME/.oxido...");
2930

30-
shell_command("mkdir", vec!["$HOME/.oxido"]);
31-
shell_command("mv", vec!["oxido* $HOME/.oxido"]);
32-
33-
println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
31+
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
32+
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
33+
}
34+
copy(
35+
"oxido",
36+
format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()),
37+
)
38+
.unwrap();
39+
remove_file("oxido").unwrap();
40+
remove_file("oxido-linux.tar.gz").unwrap();
41+
42+
println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it");
3443
}

src/installers/macos.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::{shell_command};
1+
use std::fs::{copy, metadata, remove_file, create_dir};
2+
use crate::shell_command;
23
use regex::Regex;
3-
44
pub fn install_m() {
55
let mut s = shell_command(
66
"curl",
@@ -23,12 +23,20 @@ pub fn install_m() {
2323

2424
println!("Unpacking release...");
2525

26-
shell_command("unzip", vec!["oxido*.darwin.zip"]);
26+
shell_command("unzip", vec!["oxido-darwin.zip"]);
2727

2828
println!("Moving to $HOME/.oxido...");
2929

30-
shell_command("mkdir", vec!["$HOME/.oxido"]);
31-
shell_command("mv", vec!["oxido* $HOME/.oxido"]);
32-
33-
println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
30+
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
31+
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
32+
}
33+
copy(
34+
"oxido",
35+
format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()),
36+
)
37+
.unwrap();
38+
remove_file("oxido").unwrap();
39+
remove_file("oxido-darwin.zip").unwrap();
40+
41+
println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it");
3442
}

src/installers/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn install_w() {
2020

2121
shell_command("wget", vec![&s]);
2222

23-
shell_command("unzip", vec!["oxido*.gnu.zip"]);
23+
shell_command("unzip", vec!["oxido-windows.gnu.zip"]);
2424

2525
shell_command("mkdir", vec![r"C:\bin"]);
2626

src/uninstallers/linux.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::shell_command;
2-
31
pub fn uninstall_l() {
4-
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
2+
std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap();
53
}

src/uninstallers/macos.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::shell_command;
2-
31
pub fn uninstall_m() {
4-
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
2+
std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap();
53
}

0 commit comments

Comments
 (0)