mirror of
https://github.com/coastalwhite/lemurs
synced 2024-11-22 18:13:02 +00:00
clippy: fix errors
This commit is contained in:
parent
d2c2c8b627
commit
0555485058
7 changed files with 29 additions and 33 deletions
|
@ -26,7 +26,7 @@ pub fn try_auth<'a>(
|
|||
password: &str,
|
||||
pam_service: &str,
|
||||
) -> Result<AuthUserInfo<'a>, AuthenticationError> {
|
||||
info!("Login attempt for '{}'", username);
|
||||
info!("Login attempt for '{username}'");
|
||||
|
||||
open_session(username, password, pam_service)
|
||||
.map(|(authenticator, entry)| AuthUserInfo {
|
||||
|
|
|
@ -15,7 +15,7 @@ pub enum AuthenticationError {
|
|||
impl ToString for AuthenticationError {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
AuthenticationError::PamService(service) => format!("Failed to create authenticator with PAM service '{}'", service),
|
||||
AuthenticationError::PamService(service) => format!("Failed to create authenticator with PAM service '{service}'"),
|
||||
AuthenticationError::AccountValidation => "Invalid login credentials".to_string(),
|
||||
AuthenticationError::UsernameNotFound => "Login creditionals are valid, but username is not found. This should not be possible :(".to_string(),
|
||||
AuthenticationError::SessionOpen => "Failed to open a PAM session".to_string(),
|
||||
|
|
|
@ -55,13 +55,13 @@ impl Display for CliError {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
CliError::MissingArgument(flag) => {
|
||||
write!(f, "Missing an argument for the given flag '{}'", flag)
|
||||
write!(f, "Missing an argument for the given flag '{flag}'")
|
||||
}
|
||||
CliError::InvalidTTY => {
|
||||
write!(f, "Given an invalid TTY number (only 1-12 are allowed)")
|
||||
}
|
||||
CliError::InvalidArgument(arg) => {
|
||||
write!(f, "Given an invalid flag or command '{}'", arg)
|
||||
write!(f, "Given an invalid flag or command '{arg}'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -82,7 +82,7 @@ fn setup_logger(is_preview: bool) {
|
|||
};
|
||||
|
||||
let log_file = Box::new(File::create(log_path).unwrap_or_else(|_| {
|
||||
eprintln!("Failed to open log file: '{}'", log_path);
|
||||
eprintln!("Failed to open log file: '{log_path}'");
|
||||
std::process::exit(1);
|
||||
}));
|
||||
|
||||
|
@ -94,7 +94,7 @@ fn setup_logger(is_preview: bool) {
|
|||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let cli = Cli::parse().unwrap_or_else(|err| {
|
||||
eprintln!("{}\n", err);
|
||||
eprintln!("{err}\n");
|
||||
cli::usage();
|
||||
std::process::exit(2);
|
||||
});
|
||||
|
@ -109,7 +109,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let envs = post_login::get_envs(config.environment_switcher.include_tty_shell);
|
||||
|
||||
for (env_name, _) in envs.into_iter() {
|
||||
println!("{}", env_name);
|
||||
println!("{env_name}");
|
||||
}
|
||||
}
|
||||
Commands::Cache => {
|
||||
|
@ -123,8 +123,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
info_caching::CACHE_PATH
|
||||
);
|
||||
|
||||
println!("environment: '{}'", environment);
|
||||
println!("username: '{}'", username);
|
||||
println!("environment: '{environment}'");
|
||||
println!("username: '{username}'");
|
||||
}
|
||||
Commands::Help => {
|
||||
cli::usage();
|
||||
|
@ -152,13 +152,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let uid = users::get_current_uid();
|
||||
if users::get_current_uid() != 0 {
|
||||
eprintln!("Lemurs needs to be ran as root. Found user id '{}'", uid);
|
||||
error!("Lemurs not ran as root. Found user id '{}'", uid);
|
||||
eprintln!("Lemurs needs to be ran as root. Found user id '{uid}'");
|
||||
error!("Lemurs not ran as root. Found user id '{uid}'");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if let Some(tty) = cli.tty {
|
||||
info!("Overwritten the tty to '{}' with the --tty flag", tty);
|
||||
info!("Overwritten the tty to '{tty}' with the --tty flag");
|
||||
config.tty = tty;
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
info!("Switching to tty {}", config.tty);
|
||||
|
||||
unsafe { chvt::chvt(config.tty.into()) }.unwrap_or_else(|err| {
|
||||
error!("Failed to switch tty {}. Reason: {}", config.tty, err);
|
||||
error!("Failed to switch tty {}. Reason: {err}", config.tty);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -228,11 +228,11 @@ impl From<AuthenticationError> for StartSessionError {
|
|||
}
|
||||
}
|
||||
|
||||
fn start_session<'a>(
|
||||
fn start_session(
|
||||
username: &str,
|
||||
password: &str,
|
||||
post_login_env: &PostLoginEnvironment,
|
||||
hooks: &Hooks<'a>,
|
||||
hooks: &Hooks<'_>,
|
||||
config: &Config,
|
||||
) -> Result<(), StartSessionError> {
|
||||
info!(
|
||||
|
|
|
@ -36,7 +36,7 @@ pub fn set_seat_vars(process_env: &mut EnvironmentContainer, tty: u8) {
|
|||
pub fn set_session_vars(process_env: &mut EnvironmentContainer, uid: u32) {
|
||||
info!("Setting XDG Session Variables");
|
||||
|
||||
process_env.set_or_own("XDG_RUNTIME_DIR", &format!("/run/user/{}", uid));
|
||||
process_env.set_or_own("XDG_RUNTIME_DIR", &format!("/run/user/{uid}"));
|
||||
process_env.set_or_own("XDG_SESSION_ID", "1");
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,10 @@ pub fn set_xdg_common_paths(process_env: &mut EnvironmentContainer, homedir: &st
|
|||
info!("Setting XDG Common Paths");
|
||||
|
||||
// This is according to https://wiki.archlinux.org/title/XDG_Base_Directory
|
||||
process_env.set("XDG_CONFIG_DIR", &format!("{}/.config", homedir));
|
||||
process_env.set("XDG_CACHE_HOME", &format!("{}/.cache", homedir));
|
||||
process_env.set("XDG_DATA_HOME", &format!("{}/.local/share", homedir));
|
||||
process_env.set("XDG_STATE_HOME", &format!("{}/.local/state", homedir));
|
||||
process_env.set("XDG_CONFIG_DIR", &format!("{homedir}/.config"));
|
||||
process_env.set("XDG_CACHE_HOME", &format!("{homedir}/.cache"));
|
||||
process_env.set("XDG_DATA_HOME", &format!("{homedir}/.local/share"));
|
||||
process_env.set("XDG_STATE_HOME", &format!("{homedir}/.local/state"));
|
||||
process_env.set("XDG_DATA_DIRS", "/usr/local/share:/usr/share");
|
||||
process_env.set("XDG_CONFIG_DIRS", "/etc/xdg");
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ impl Display for EnvironmentStartError {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::WaylandStart => f.write_str("Failed to start Wayland compositor"),
|
||||
Self::XSetup(err) => write!(f, "Failed to setup X11 server. Reason: '{}'", err),
|
||||
Self::XSetup(err) => write!(f, "Failed to setup X11 server. Reason: '{err}'"),
|
||||
Self::XStartEnv => f.write_str("Failed to start X11 client"),
|
||||
Self::TTYStart => f.write_str("Failed to start TTY"),
|
||||
}
|
||||
|
@ -156,9 +156,9 @@ impl SpawnedEnvironment {
|
|||
}
|
||||
|
||||
impl PostLoginEnvironment {
|
||||
pub fn spawn<'a>(
|
||||
pub fn spawn(
|
||||
&self,
|
||||
user_info: &AuthUserInfo<'a>,
|
||||
user_info: &AuthUserInfo<'_>,
|
||||
process_env: &mut EnvironmentContainer,
|
||||
_config: &Config,
|
||||
) -> Result<SpawnedEnvironment, EnvironmentStartError> {
|
||||
|
@ -198,7 +198,7 @@ impl PostLoginEnvironment {
|
|||
{
|
||||
Ok(child) => child,
|
||||
Err(err) => {
|
||||
error!("Failed to start Wayland Compositor. Reason '{}'", err);
|
||||
error!("Failed to start Wayland Compositor. Reason '{err}'");
|
||||
return Err(EnvironmentStartError::WaylandStart);
|
||||
}
|
||||
};
|
||||
|
@ -220,7 +220,7 @@ impl PostLoginEnvironment {
|
|||
{
|
||||
Ok(child) => child,
|
||||
Err(err) => {
|
||||
error!("Failed to start TTY shell. Reason '{}'", err);
|
||||
error!("Failed to start TTY shell. Reason '{err}'");
|
||||
return Err(EnvironmentStartError::TTYStart);
|
||||
}
|
||||
};
|
||||
|
@ -245,8 +245,7 @@ pub fn get_envs(with_tty_shell: bool) -> Vec<(String, PostLoginEnvironment)> {
|
|||
if let Ok(metadata) = path.metadata() {
|
||||
if std::os::unix::fs::MetadataExt::mode(&metadata) & 0o111 == 0 {
|
||||
warn!(
|
||||
"'{}' is not executable and therefore not added as an environment",
|
||||
file_name
|
||||
"'{file_name}' is not executable and therefore not added as an environment",
|
||||
);
|
||||
|
||||
continue;
|
||||
|
|
|
@ -48,7 +48,7 @@ fn mcookie() -> String {
|
|||
// available?
|
||||
let mut rng = rand::thread_rng();
|
||||
let cookie: u128 = rng.gen();
|
||||
format!("{:032x}", cookie)
|
||||
format!("{cookie:032x}")
|
||||
}
|
||||
|
||||
pub fn setup_x(
|
||||
|
@ -94,7 +94,7 @@ pub fn setup_x(
|
|||
process_env.set("XAUTHORITY", xauth_path);
|
||||
|
||||
let doubledigit_vtnr = if vtnr_value.len() == 1 {
|
||||
format!("0{}", vtnr_value)
|
||||
format!("0{vtnr_value}")
|
||||
} else {
|
||||
vtnr_value
|
||||
};
|
||||
|
@ -102,10 +102,7 @@ pub fn setup_x(
|
|||
info!("Run X server");
|
||||
let child = Command::new(super::SYSTEM_SHELL)
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"/usr/bin/X {} vt{}",
|
||||
display_value, doubledigit_vtnr
|
||||
))
|
||||
.arg(format!("/usr/bin/X {display_value} vt{doubledigit_vtnr}",))
|
||||
.stdout(Stdio::null()) // TODO: Maybe this should be logged or something?
|
||||
.stderr(Stdio::null()) // TODO: Maybe this should be logged or something?
|
||||
.spawn()
|
||||
|
|
Loading…
Reference in a new issue