Skip to content

Commit

Permalink
Fix compilation of code for getting device information on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Oct 29, 2023
1 parent 7f23c00 commit a55e427
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fclones/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ fn scan_files(ctx: &GroupCtx<'_>) -> Vec<Vec<FileInfo>> {
walk.follow_links = config.follow_links;
walk.report_links = config.symbolic_links;
walk.no_ignore = config.no_ignore;
walk.same_fs = config.one_fs;
walk.one_fs = config.one_fs;
walk.path_selector = ctx.path_selector.clone();
walk.log = Some(ctx.log);
walk.on_visit = spinner_tick;
Expand Down
31 changes: 23 additions & 8 deletions fclones/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ impl IgnoreStack {
}
}

#[cfg(unix)]
type DeviceId = u64;

#[cfg(windows)]
type DeviceId = u128;

/// Describes walk configuration.
/// Many walks can be initiated from the same instance.
pub struct Walk<'a> {
Expand All @@ -144,7 +140,7 @@ pub struct Walk<'a> {
/// Don't honor .gitignore and .fdignore.
pub no_ignore: bool,
/// Don't leave the fs of the root paths.
pub same_fs: bool,
pub one_fs: bool,
/// Controls selecting or ignoring files by matching file and path names with regexes / globs.
pub path_selector: PathSelector,
/// The function to call for each visited file. The directories are not reported.
Expand All @@ -170,7 +166,7 @@ impl<'a> Walk<'a> {
follow_links: false,
report_links: false,
no_ignore: false,
same_fs: false,
one_fs: false,
path_selector: PathSelector::new(base_dir),
on_visit: &|_| {},
log: None,
Expand Down Expand Up @@ -207,11 +203,30 @@ impl<'a> Walk<'a> {
"Skipping directory {} because recursive scan is disabled.",
p.display()
)),
#[cfg(unix)]
Ok(metadata) => {
let dev = FileId::from_metadata(&metadata).device;
let state = &state;
scope.spawn(move |scope| self.visit_path(p, dev, scope, 0, ignore, state))
}
#[cfg(windows)]
Ok(_) => {
let dev = FileId::new(&p).map(|f| f.device);
match dev {
Err(err) if self.one_fs => self.log_warn(format!(
"Failed to get device information for {}: {}",
p.display(),
err
)),
_ => {
let dev = dev.unwrap_or_default();
let state = &state;
scope.spawn(move |scope| {
self.visit_path(p, dev, scope, 0, ignore, state)
})
}
}
}
Err(err) => {
self.log_warn(format!("Cannot stat {}: {}", p.display(), err));
}
Expand Down Expand Up @@ -316,7 +331,7 @@ impl<'a> Walk<'a> {
match self.resolve_link(&path) {
Ok((_, EntryType::File)) if self.report_links => self.visit_file(path, state),
Ok((target, _)) => {
if self.follow_links && (!self.same_fs || self.same_fs(&target, dev)) {
if self.follow_links && (!self.one_fs || self.same_fs(&target, dev)) {
self.visit_path(target, dev, scope, level, gitignore, state);
}
}
Expand Down Expand Up @@ -345,7 +360,7 @@ impl<'a> Walk<'a> {
if !self.path_selector.matches_dir(&path) {
return;
}
if self.same_fs && !self.same_fs(&path, dev) {
if self.one_fs && !self.same_fs(&path, dev) {
return;
}

Expand Down

0 comments on commit a55e427

Please sign in to comment.