Skip to content

Commit

Permalink
fix: Handle Interrupted Error
Browse files Browse the repository at this point in the history
Rust may throw Interrupted errors while scanning filesystem. These may
be retried:
https://doc.rust-lang.org/std/io/enum.ErrorKind.html#variant.Interrupted
  • Loading branch information
bootandy committed Jan 25, 2025
1 parent 9ba0b6d commit db6ab76
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
56 changes: 40 additions & 16 deletions src/dir_walker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cmp::Ordering;
use std::fs;
use std::io::Error;
use std::sync::Arc;
use std::sync::Mutex;

Expand Down Expand Up @@ -229,30 +230,21 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
}
}
Err(ref failed) => {
let mut editable_error = errors.lock().unwrap();
editable_error.no_permissions.insert(failed.to_string());
if handle_error_and_retry(failed, &dir, walk_data) {
return walk(dir.clone(), walk_data, depth);
}
}
}
None
})
.collect()
}
Err(failed) => {
let mut editable_error = errors.lock().unwrap();
match failed.kind() {
std::io::ErrorKind::PermissionDenied => {
editable_error
.no_permissions
.insert(dir.to_string_lossy().into());
}
std::io::ErrorKind::NotFound => {
editable_error.file_not_found.insert(failed.to_string());
}
_ => {
editable_error.unknown_error.insert(failed.to_string());
}
if handle_error_and_retry(&failed, &dir, walk_data) {
return walk(dir, walk_data, depth);
} else {
vec![]
}
vec![]
}
}
} else {
Expand All @@ -274,6 +266,38 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
build_node(dir, children, is_symlink, false, depth, walk_data)
}

fn handle_error_and_retry(failed: &Error, dir: &Path, walk_data: &WalkData) -> bool {

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (ubuntu-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (macos-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / MinSRV

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (macos-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (ubuntu-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / MinSRV

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, arm-unknown-linux-musleabi, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, arm-unknown-linux-gnueabihf, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, arm-unknown-linux-musleabi, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-musl, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, arm-unknown-linux-gnueabihf, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, use-cross)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

cannot find type `Path` in this scope

Check failure on line 269 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

cannot find type `Path` in this scope
let mut editable_error = walk_data.errors.lock().unwrap();
match failed.kind() {
std::io::ErrorKind::PermissionDenied => {
editable_error
.no_permissions
.insert(dir.to_string_lossy().into());
}
std::io::ErrorKind::InvalidInput => {
editable_error
.no_permissions
.insert(dir.to_string_lossy().into());
}
std::io::ErrorKind::NotFound => {
editable_error.file_not_found.insert(failed.to_string());
}
std::io::ErrorKind::Interrupted => {
let mut editable_error = walk_data.errors.lock().unwrap();
editable_error.interrupted_error += 1;
if editable_error.interrupted_error > 3 {
panic!("Multiple Interrupted Errors occurred while scanning filesystem. Aborting");
} else {
return true;
}
}
_ => {
editable_error.unknown_error.insert(failed.to_string());
}
}
false
}

mod tests {

#[allow(unused_imports)]
Expand Down
1 change: 1 addition & 0 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct RuntimeErrors {
pub no_permissions: HashSet<String>,
pub file_not_found: HashSet<String>,
pub unknown_error: HashSet<String>,
pub interrupted_error: i32,
pub abort: bool,
}

Expand Down

0 comments on commit db6ab76

Please sign in to comment.