Skip to content

Commit

Permalink
Don't crash when found file name which is not valid Unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Oct 6, 2020
1 parent 78aa7d5 commit 3b63798
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
21 changes: 18 additions & 3 deletions czkawka_core/src/big_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ impl BigFile {
}

let mut is_excluded_dir = false;
next_folder = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap() + "/";
next_folder = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
+ "/";

for ed in &self.directories.excluded_directories {
if next_folder == *ed {
Expand All @@ -171,7 +177,11 @@ impl BigFile {
}
} else if metadata.is_file() {
let mut have_valid_extension: bool;
let file_name_lowercase: String = entry_data.file_name().into_string().unwrap().to_lowercase();
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
.to_lowercase();

// Checking allowed extensions
if !self.allowed_extensions.file_extensions.is_empty() {
Expand All @@ -188,7 +198,12 @@ impl BigFile {

// Checking files
if have_valid_extension {
let current_file_name = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap();
let current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
};

// Checking expressions
let mut found_expression: bool = false;
Expand Down
21 changes: 18 additions & 3 deletions czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ impl DuplicateFinder {
}

let mut is_excluded_dir = false;
next_folder = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap() + "/";
next_folder = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
+ "/";

for ed in &self.directories.excluded_directories {
if next_folder == *ed {
Expand All @@ -253,7 +259,11 @@ impl DuplicateFinder {
}
} else if metadata.is_file() {
let mut have_valid_extension: bool;
let file_name_lowercase: String = entry_data.file_name().into_string().unwrap().to_lowercase();
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
.to_lowercase();

// Checking allowed extensions
if !self.allowed_extensions.file_extensions.is_empty() {
Expand All @@ -270,7 +280,12 @@ impl DuplicateFinder {

// Checking files
if metadata.len() >= self.minimal_file_size && have_valid_extension {
let current_file_name = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap();
let current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
};

// Checking expressions
let mut found_expression: bool = false;
Expand Down
21 changes: 18 additions & 3 deletions czkawka_core/src/empty_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ impl EmptyFiles {
}

let mut is_excluded_dir = false;
next_folder = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap() + "/";
next_folder = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
+ "/";

for ed in &self.directories.excluded_directories {
if next_folder == *ed {
Expand All @@ -197,7 +203,11 @@ impl EmptyFiles {
}
} else if metadata.is_file() {
let mut have_valid_extension: bool;
let file_name_lowercase: String = entry_data.file_name().into_string().unwrap().to_lowercase();
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
.to_lowercase();

// Checking allowed extensions
if !self.allowed_extensions.file_extensions.is_empty() {
Expand All @@ -214,7 +224,12 @@ impl EmptyFiles {

// Checking files
if metadata.len() == 0 && have_valid_extension {
let current_file_name = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap();
let current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
};

// Checking expressions
let mut found_expression: bool = false;
Expand Down
8 changes: 7 additions & 1 deletion czkawka_core/src/empty_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ impl EmptyFolder {
};
// If child is dir, still folder may be considered as empty if all children are only directories.
if metadata.is_dir() {
next_folder = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap() + "/";
next_folder = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
+ "/";
folders_to_check.push(next_folder.clone());

folders_checked.insert(
Expand Down
21 changes: 18 additions & 3 deletions czkawka_core/src/temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ impl Temporary {
}

let mut is_excluded_dir = false;
next_folder = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap() + "/";
next_folder = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
+ "/";

for ed in &self.directories.excluded_directories {
if next_folder == *ed {
Expand All @@ -188,7 +194,11 @@ impl Temporary {
folders_to_check.push(next_folder);
}
} else if metadata.is_file() {
let file_name_lowercase: String = entry_data.file_name().into_string().unwrap().to_lowercase();
let file_name_lowercase: String = match entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
}
.to_lowercase();
let mut is_temporary_file: bool = false;

// Temporary files which needs to have dot in name(not sure if exists without dot)
Expand All @@ -204,7 +214,12 @@ impl Temporary {

// Checking files
if is_temporary_file {
let current_file_name = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap();
let current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
Err(_) => continue,
};

// Checking expressions
let mut found_expression: bool = false;
Expand Down

0 comments on commit 3b63798

Please sign in to comment.