Fix missing lints - Docs need to be improved still

This commit is contained in:
Dietrich 2020-11-09 13:58:13 +01:00
parent 467c8ee007
commit 8fcd32eca2
5 changed files with 40 additions and 38 deletions

View File

@ -1,8 +1,14 @@
[package]
name = "adduser"
version = "0.1.0"
description = "Library for managing Linux users and their directories"
authors = ["Dietrich <dietrich@teilgedanken.de>"]
edition = "2018"
license = "MIT OR Apache-2.0"
keywords = ["user", "admin", "linux", "manage"]
categories = ["system-tools", "system-tools::user-management"]
repository = "https://git.teilgedanken.de/Rust/useradd/"
readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

1
README.md Normal file
View File

@ -0,0 +1 @@
# Usermanager written in Rust

View File

@ -6,6 +6,7 @@
clippy::cargo
)]
//#![allow(clippy::non_ascii_literal)]
#![allow(clippy::missing_errors_doc)]
#[macro_use]
extern crate lazy_static;

View File

@ -67,6 +67,21 @@ pub struct LockedFileGuard {
path: PathBuf,
pub(crate) file: File,
}
struct TempLockFile {
tlf: PathBuf,
}
impl Drop for TempLockFile {
fn drop(&mut self) {
info!("removing temporary lockfile {}", self.tlf.to_str().unwrap());
std::fs::remove_file(&self.tlf).unwrap();
}
}
impl Deref for TempLockFile {
type Target = PathBuf;
fn deref(&self) -> &PathBuf {
&self.tlf
}
}
impl LockedFileGuard {
pub fn new(path: &PathBuf) -> Result<Self, crate::UserLibError> {
@ -118,22 +133,6 @@ impl LockedFileGuard {
/// * try to lock again now that the old logfile has been safely removed.
/// * remove the original file and only keep the lock hardlink
fn try_to_lock_file(path: &PathBuf) -> Result<(PathBuf, File), crate::UserLibError> {
struct TempLockFile {
tlf: PathBuf,
}
impl Drop for TempLockFile {
fn drop(&mut self) {
info!("removing temporary lockfile {}", self.tlf.to_str().unwrap());
std::fs::remove_file(&self.tlf).unwrap();
}
}
impl Deref for TempLockFile {
type Target = PathBuf;
fn deref(&self) -> &PathBuf {
&self.tlf
}
}
info!("locking file {}", path.to_string_lossy());
let mut tempfilepath_const = path.clone();
// get the pid

View File

@ -187,31 +187,26 @@ impl UserDBWrite for UserDBLocal {
Self::delete_home(user)?;
}
let group = self.get_group_pos_by_id(user.get_gid());
match group {
Some((group, id)) => {
if group
.get_member_names()
.expect("groups have to have members")
.len()
== 1
{
UserDBLocal::delete_from_group(
group,
&group_file_content,
&mut locked_g,
)?;
let _gres = self.groups.remove(id);
} else {
warn!(
"The primary group {} was not empty and is thus not removed.",
group.get_groupname().unwrap()
);
}
if let Some((group, id)) = group {
if group
.get_member_names()
.expect("groups have to have members")
.len()
== 1
{
Self::delete_from_group(group, &group_file_content, &mut locked_g)?;
let _gres = self.groups.remove(id);
} else {
warn!(
"The primary group {} was not empty and is thus not removed.",
group.get_groupname().unwrap()
);
}
None => warn!(
} else {
warn!(
"The users primary group could not be found {}",
user.get_gid()
),
)
}
// Remove the user from the memory database(HashMap)
let res = self.users.remove(args.username);