Skip to content

Fix clippy::type_complexity, suspicious_open_options, nonminimal_bool #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion file/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ fn evaluate_expression(
Expr::Newer(f) => {
if let Ok(metadata) = fs::metadata(f) {
if let Ok(file_metadata) = file.metadata() {
if !(file_metadata.modified().unwrap() > metadata.modified().unwrap()) {
if file_metadata.modified().unwrap() <= metadata.modified().unwrap() {
c_files.remove(file.path());
}
}
Expand Down
1 change: 1 addition & 0 deletions m4/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn update_snapshots(args: &Args, update: &UpdateSnapshots) {
}
let mut f = std::fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(snapshot_file)
.unwrap();
Expand Down
6 changes: 4 additions & 2 deletions tree/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::{
path::{Path, PathBuf},
};

pub type InodeMap = HashMap<(u64, u64), (ftw::FileDescriptor, CString)>;

/// Return the error message.
///
/// This is for compatibility with coreutils mv. `format!("{e}")` will append
Expand Down Expand Up @@ -441,7 +443,7 @@ pub fn copy_file<F>(
source_arg: &Path,
target_arg: &Path,
created_files: &mut HashSet<PathBuf>,
mut inode_map: Option<&mut HashMap<(u64, u64), (ftw::FileDescriptor, CString)>>,
mut inode_map: Option<&mut InodeMap>,
prompt_fn: F,
) -> io::Result<()>
where
Expand Down Expand Up @@ -646,7 +648,7 @@ pub fn copy_files<F>(
cfg: &CopyConfig,
sources: &[PathBuf],
target: &Path,
mut inode_map: Option<&mut HashMap<(u64, u64), (ftw::FileDescriptor, CString)>>,
mut inode_map: Option<&mut InodeMap>,
prompt_fn: F,
) -> Option<()>
where
Expand Down
28 changes: 19 additions & 9 deletions users/talk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ struct Args {
ttyname: Option<String>,
}

pub struct State {
pub msg_bytes1: Vec<u8>,
pub msg_bytes2: Vec<u8>,
pub socket: Arc<UdpSocket>,
pub talkd_addr: SocketAddr,
}

/// A static variable to hold the state of delete invitations on SIGINT signal.
static DELETE_INVITATIONS: LazyLock<
Arc<Mutex<Option<(Vec<u8>, Vec<u8>, Arc<UdpSocket>, SocketAddr)>>>,
> = LazyLock::new(|| Arc::new(Mutex::new(None)));
static DELETE_INVITATIONS: LazyLock<Arc<Mutex<Option<State>>>> =
LazyLock::new(|| Arc::new(Mutex::new(None)));

/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
const BUFFER_SIZE: usize = 12;
Expand Down Expand Up @@ -947,7 +953,13 @@ fn handle_new_invitation(

let clone_socket = Arc::clone(&socket);

*DELETE_INVITATIONS.lock().unwrap() = Some((msg_bytes1, msg_bytes2, clone_socket, talkd_addr));
*DELETE_INVITATIONS.lock().unwrap() = Some(State {
msg_bytes1,
msg_bytes2,
socket: clone_socket,
talkd_addr,
});

// Start listening for incoming TCP connections.
for stream in listener.incoming() {
match stream {
Expand Down Expand Up @@ -1613,12 +1625,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
eprintln!("Connection closed, exiting...");

// Lock the DELETE_INVITATIONS mutex and check for an existing invitation
if let Some((msg_bytes1, msg_bytes2, socket, talkd_addr)) =
DELETE_INVITATIONS.lock().unwrap().as_ref()
{
if let Some(state) = DELETE_INVITATIONS.lock().unwrap().as_ref() {
// Handle the deletion of invitations
handle_delete_invitations(socket, msg_bytes1, talkd_addr);
handle_delete_invitations(socket, msg_bytes2, talkd_addr);
handle_delete_invitations(&state.socket, &state.msg_bytes1, &state.talkd_addr);
handle_delete_invitations(&state.socket, &state.msg_bytes2, &state.talkd_addr);
}

// Exit the process with a code indicating the signal received
Expand Down