Compare commits
No commits in common. "064081a0c3cc0f76d3c8ac880a3139a8cebd97f8" and "00542f11d395a906302d6ddf7e79a5e8d53b19b1" have entirely different histories.
064081a0c3
...
00542f11d3
38
src/install_check.rs
Normal file
38
src/install_check.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
Rust Arch Linux Updater
|
||||||
|
Copyright (C) 2024 Luke Harding <luke@lukeh990.io>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
install_check.rs
|
||||||
|
This module allows for checking if any file is present on the filesystem
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
use std::fmt::Formatter;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct NotInstalledError {
|
||||||
|
file_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for NotInstalledError {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{} not found.", self.file_name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(path: impl Into<String>) -> Result<(), NotInstalledError> {
|
||||||
|
let path = path.into();
|
||||||
|
let exists = Path::new(&path).exists();
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(NotInstalledError { file_name: path })
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
use colored::{ColoredString, Colorize};
|
use colored::{ColoredString, Colorize};
|
||||||
|
|
||||||
|
mod install_check;
|
||||||
mod pacman_api;
|
mod pacman_api;
|
||||||
mod shell_commands;
|
mod shell_commands;
|
||||||
|
|
||||||
@ -29,7 +30,6 @@ fn main() {
|
|||||||
notice_println("Running pacman update");
|
notice_println("Running pacman update");
|
||||||
if let Err(e) = pacman_api::update_all() {
|
if let Err(e) = pacman_api::update_all() {
|
||||||
error_println(e.to_string());
|
error_println(e.to_string());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notice_println("Move onto something else");
|
notice_println("Move onto something else");
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
use std::{error, fmt};
|
use std::{error, fmt};
|
||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
use std::io::Read;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::shell_commands;
|
use crate::shell_commands;
|
||||||
@ -67,26 +66,9 @@ pub fn check() -> Result<(), PacmanError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_all() -> Result<(), PacmanError> {
|
pub fn update_all() -> Result<(), PacmanError> {
|
||||||
let out = match shell_commands::execute_in_sh("pacman -Syu") {
|
if let Err(e) = shell_commands::execute_in_sh("sudo pacman -Syu") {
|
||||||
Ok(out) => out,
|
|
||||||
Err(e) => return Err(PacmanError::Other(e.to_string())),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut child_stderr = match out.stderr {
|
|
||||||
Some(stderr) => stderr,
|
|
||||||
None => return Ok(()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut stderr_out = String::new();
|
|
||||||
if let Err(e) = child_stderr.read_to_string(&mut stderr_out) {
|
|
||||||
return Err(PacmanError::Other(e.to_string()));
|
return Err(PacmanError::Other(e.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if stderr_out.is_empty() {
|
Ok(())
|
||||||
Ok(())
|
|
||||||
} else if stderr_out == "error: you cannot perform this operation unless you are root.\n" {
|
|
||||||
Err(PacmanError::InsufficientPrivilege)
|
|
||||||
} else {
|
|
||||||
Err(PacmanError::Other(stderr_out))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,24 +13,21 @@
|
|||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process::{Child, Command, Output, Stdio};
|
use std::process::{Command, Output};
|
||||||
|
|
||||||
pub fn execute_and_display<S: AsRef<OsStr>, I>(cmd: S, args: I) -> io::Result<Child>
|
pub fn execute_and_display<S: AsRef<OsStr>, I>(cmd: S, args: I) -> io::Result<()>
|
||||||
where
|
where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
I::Item: AsRef<OsStr>,
|
I::Item: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
let mut child = Command::new(cmd)
|
let mut child = Command::new(cmd).args(args).spawn()?;
|
||||||
.args(args)
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()?;
|
|
||||||
|
|
||||||
child.wait()?;
|
child.wait()?;
|
||||||
|
|
||||||
Ok(child)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_in_sh(cmd: &'static str) -> io::Result<Child> {
|
pub fn execute_in_sh(cmd: &'static str) -> io::Result<()> {
|
||||||
execute_and_display("sh", ["-c", cmd])
|
execute_and_display("sh", ["-c", cmd])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user