Skip to content

Commit

Permalink
Clean up unused generated during Windows platform build process. (#448)
Browse files Browse the repository at this point in the history
* Fix Windows' warning in build.

* Fix Windows' warning in build.

* Fix Windows' warning in build.

* Run cargo fmt.
  • Loading branch information
hanbings authored Sep 5, 2024
1 parent f9d74ad commit db8e265
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
59 changes: 33 additions & 26 deletions src/find/matchers/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// 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,
Expand All @@ -31,6 +24,13 @@ pub struct Cache {
///
/// This is only supported on Unix.
#[cfg(unix)]
use std::{
cell::RefCell,
error::Error,
io::{stderr, Write},
path::Path,
};
#[cfg(unix)]
pub fn get_file_system_type(
path: &Path,
cache: &RefCell<Option<Cache>>,
Expand Down Expand Up @@ -74,42 +74,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<Option<Cache>>,
}

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)]
Expand Down
5 changes: 4 additions & 1 deletion src/find/matchers/type_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ 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;

#[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};

Expand Down

0 comments on commit db8e265

Please sign in to comment.