Skip to content

Commit 417730d

Browse files
authored
Merge pull request #285 from fox0/clippy--nonminimal_bool
Fix clippy::type_complexity, suspicious_open_options, nonminimal_bool
2 parents ae140c5 + be79673 commit 417730d

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

file/find.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn evaluate_expression(
388388
Expr::Newer(f) => {
389389
if let Ok(metadata) = fs::metadata(f) {
390390
if let Ok(file_metadata) = file.metadata() {
391-
if !(file_metadata.modified().unwrap() > metadata.modified().unwrap()) {
391+
if file_metadata.modified().unwrap() <= metadata.modified().unwrap() {
392392
c_files.remove(file.path());
393393
}
394394
}

m4/test-manager/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn update_snapshots(args: &Args, update: &UpdateSnapshots) {
155155
}
156156
let mut f = std::fs::OpenOptions::new()
157157
.write(true)
158+
.truncate(true)
158159
.create(true)
159160
.open(snapshot_file)
160161
.unwrap();

tree/common/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use std::{
1919
path::{Path, PathBuf},
2020
};
2121

22+
pub type InodeMap = HashMap<(u64, u64), (ftw::FileDescriptor, CString)>;
23+
2224
/// Return the error message.
2325
///
2426
/// This is for compatibility with coreutils mv. `format!("{e}")` will append
@@ -441,7 +443,7 @@ pub fn copy_file<F>(
441443
source_arg: &Path,
442444
target_arg: &Path,
443445
created_files: &mut HashSet<PathBuf>,
444-
mut inode_map: Option<&mut HashMap<(u64, u64), (ftw::FileDescriptor, CString)>>,
446+
mut inode_map: Option<&mut InodeMap>,
445447
prompt_fn: F,
446448
) -> io::Result<()>
447449
where
@@ -646,7 +648,7 @@ pub fn copy_files<F>(
646648
cfg: &CopyConfig,
647649
sources: &[PathBuf],
648650
target: &Path,
649-
mut inode_map: Option<&mut HashMap<(u64, u64), (ftw::FileDescriptor, CString)>>,
651+
mut inode_map: Option<&mut InodeMap>,
650652
prompt_fn: F,
651653
) -> Option<()>
652654
where

users/talk.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ struct Args {
4545
ttyname: Option<String>,
4646
}
4747

48+
pub struct State {
49+
pub msg_bytes1: Vec<u8>,
50+
pub msg_bytes2: Vec<u8>,
51+
pub socket: Arc<UdpSocket>,
52+
pub talkd_addr: SocketAddr,
53+
}
54+
4855
/// A static variable to hold the state of delete invitations on SIGINT signal.
49-
static DELETE_INVITATIONS: LazyLock<
50-
Arc<Mutex<Option<(Vec<u8>, Vec<u8>, Arc<UdpSocket>, SocketAddr)>>>,
51-
> = LazyLock::new(|| Arc::new(Mutex::new(None)));
56+
static DELETE_INVITATIONS: LazyLock<Arc<Mutex<Option<State>>>> =
57+
LazyLock::new(|| Arc::new(Mutex::new(None)));
5258

5359
/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
5460
const BUFFER_SIZE: usize = 12;
@@ -954,7 +960,13 @@ fn handle_new_invitation(
954960

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

957-
*DELETE_INVITATIONS.lock().unwrap() = Some((msg_bytes1, msg_bytes2, clone_socket, talkd_addr));
963+
*DELETE_INVITATIONS.lock().unwrap() = Some(State {
964+
msg_bytes1,
965+
msg_bytes2,
966+
socket: clone_socket,
967+
talkd_addr,
968+
});
969+
958970
// Start listening for incoming TCP connections.
959971
for stream in listener.incoming() {
960972
match stream {
@@ -1620,12 +1632,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
16201632
eprintln!("Connection closed, exiting...");
16211633

16221634
// Lock the DELETE_INVITATIONS mutex and check for an existing invitation
1623-
if let Some((msg_bytes1, msg_bytes2, socket, talkd_addr)) =
1624-
DELETE_INVITATIONS.lock().unwrap().as_ref()
1625-
{
1635+
if let Some(state) = DELETE_INVITATIONS.lock().unwrap().as_ref() {
16261636
// Handle the deletion of invitations
1627-
handle_delete_invitations(socket, msg_bytes1, talkd_addr);
1628-
handle_delete_invitations(socket, msg_bytes2, talkd_addr);
1637+
handle_delete_invitations(&state.socket, &state.msg_bytes1, &state.talkd_addr);
1638+
handle_delete_invitations(&state.socket, &state.msg_bytes2, &state.talkd_addr);
16291639
}
16301640

16311641
// Exit the process with a code indicating the signal received

0 commit comments

Comments
 (0)