Skip to content
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

Clean up unused generated during Windows platform build process. #448

Merged
merged 4 commits into from
Sep 5, 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
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 @@
///
/// 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 @@
///
/// 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(),

Check warning on line 105 in src/find/matchers/fs.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/fs.rs#L104-L105

Added lines #L104 - L105 were not covered by tests
"Error getting filesystem type for {}",
file_info.path().to_string_lossy()

Check warning on line 107 in src/find/matchers/fs.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/fs.rs#L107

Added line #L107 was not covered by tests
)
.unwrap();

Check warning on line 109 in src/find/matchers/fs.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/fs.rs#L109

Added line #L109 was not covered by tests

false

Check warning on line 111 in src/find/matchers/fs.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/fs.rs#L111

Added line #L111 was not covered by tests
}
}
}

#[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
Loading