From 5df7474ff3d552df0f2ca985aa8b352a448dbdb6 Mon Sep 17 00:00:00 2001 From: hanbings Date: Mon, 2 Sep 2024 13:52:45 +0800 Subject: [PATCH 1/4] Fix Windows' warning in build. --- src/find/matchers/fs.rs | 55 ++++++++++++++++++------------- src/find/matchers/type_matcher.rs | 2 +- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/find/matchers/fs.rs b/src/find/matchers/fs.rs index 6229efef..0ae33e07 100644 --- a/src/find/matchers/fs.rs +++ b/src/find/matchers/fs.rs @@ -4,15 +4,11 @@ // file that was distributed with this source code. use std::cell::RefCell; -use std::path::Path; -use std::{ - error::Error, - io::{stderr, Write}, -}; use super::{Matcher, MatcherIO, WalkEntry}; /// The latest mapping from dev_id to fs_type, used for saving mount info reads +#[cfg(unix)] pub struct Cache { dev_id: String, fs_type: String, @@ -31,6 +27,12 @@ pub struct Cache { /// /// This is only supported on Unix. #[cfg(unix)] +use std::{ + error::Error, + io::{stderr, Write}, + path::Path, +}; +#[cfg(unix)] pub fn get_file_system_type( path: &Path, cache: &RefCell>, @@ -74,42 +76,49 @@ pub fn get_file_system_type( /// /// This is only supported on Unix. pub struct FileSystemMatcher { + #[cfg(unix)] fs_text: String, + #[cfg(unix)] cache: RefCell>, } impl FileSystemMatcher { + #[cfg(unix)] pub fn new(fs_text: String) -> Self { Self { fs_text, cache: RefCell::new(None), } } + + #[cfg(not(unix))] + pub fn new(_fs_text: String) -> Self { + Self {} + } } impl Matcher for FileSystemMatcher { + #[cfg(unix)] fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool { - #[cfg(not(unix))] - { - false - } - #[cfg(unix)] - { - match get_file_system_type(file_info.path(), &self.cache) { - Ok(result) => result == self.fs_text, - Err(_) => { - writeln!( - &mut stderr(), - "Error getting filesystem type for {}", - file_info.path().to_string_lossy() - ) - .unwrap(); - - false - } + match get_file_system_type(file_info.path(), &self.cache) { + Ok(result) => result == self.fs_text, + Err(_) => { + writeln!( + &mut stderr(), + "Error getting filesystem type for {}", + file_info.path().to_string_lossy() + ) + .unwrap(); + + false } } } + + #[cfg(not(unix))] + fn matches(&self, _file_info: &WalkEntry, _: &mut MatcherIO) -> bool { + false + } } #[cfg(test)] diff --git a/src/find/matchers/type_matcher.rs b/src/find/matchers/type_matcher.rs index 017839c7..9465ff5c 100644 --- a/src/find/matchers/type_matcher.rs +++ b/src/find/matchers/type_matcher.rs @@ -87,7 +87,7 @@ impl Matcher for XtypeMatcher { #[cfg(test)] mod tests { use super::*; - use crate::find::matchers::tests::{get_dir_entry_follow, get_dir_entry_for}; + use crate::find::matchers::tests::get_dir_entry_for; use crate::find::tests::FakeDependencies; use std::io::ErrorKind; From ead4718614e0f683e1b887251fd82dbc02b31170 Mon Sep 17 00:00:00 2001 From: hanbings Date: Mon, 2 Sep 2024 13:56:00 +0800 Subject: [PATCH 2/4] Fix Windows' warning in build. --- src/find/matchers/type_matcher.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/find/matchers/type_matcher.rs b/src/find/matchers/type_matcher.rs index 9465ff5c..95696c91 100644 --- a/src/find/matchers/type_matcher.rs +++ b/src/find/matchers/type_matcher.rs @@ -94,6 +94,9 @@ mod tests { #[cfg(unix)] use std::os::unix::fs::symlink; + #[cfg(unix)] + use crate::find::matchers::tests::get_dir_entry_follow; + #[cfg(windows)] use std::os::windows::fs::{symlink_dir, symlink_file}; From d7f10e167cd5357ef145faf848c9d4862e34e643 Mon Sep 17 00:00:00 2001 From: hanbings Date: Mon, 2 Sep 2024 13:59:48 +0800 Subject: [PATCH 3/4] Fix Windows' warning in build. --- src/find/matchers/fs.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/find/matchers/fs.rs b/src/find/matchers/fs.rs index 0ae33e07..9c523d08 100644 --- a/src/find/matchers/fs.rs +++ b/src/find/matchers/fs.rs @@ -2,9 +2,6 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. - -use std::cell::RefCell; - use super::{Matcher, MatcherIO, WalkEntry}; /// The latest mapping from dev_id to fs_type, used for saving mount info reads @@ -31,6 +28,7 @@ use std::{ error::Error, io::{stderr, Write}, path::Path, + cell::RefCell, }; #[cfg(unix)] pub fn get_file_system_type( From c8312a1ec12d13792629b1e40e72d4fee87df0f4 Mon Sep 17 00:00:00 2001 From: hanbings Date: Mon, 2 Sep 2024 14:00:56 +0800 Subject: [PATCH 4/4] Run cargo fmt. --- src/find/matchers/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/find/matchers/fs.rs b/src/find/matchers/fs.rs index 9c523d08..7722be45 100644 --- a/src/find/matchers/fs.rs +++ b/src/find/matchers/fs.rs @@ -25,10 +25,10 @@ pub struct Cache { /// This is only supported on Unix. #[cfg(unix)] use std::{ + cell::RefCell, error::Error, io::{stderr, Write}, path::Path, - cell::RefCell, }; #[cfg(unix)] pub fn get_file_system_type(