Update to Rust 1.5.1 (#302)

This commit is contained in:
Rafał Mikrut 2021-03-27 13:14:02 +01:00 committed by GitHub
parent ce8161fd7e
commit 50ad3f9873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 174 additions and 709 deletions

699
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -256,8 +256,8 @@ impl FileToSave {
fn parse_hash_type(src: &str) -> Result<HashType, &'static str> {
match src.to_ascii_lowercase().as_str() {
"blake3" => Ok(HashType::Blake3),
"crc32" => Ok(HashType::CRC32),
"xxh3" => Ok(HashType::XXH3),
"crc32" => Ok(HashType::Crc32),
"xxh3" => Ok(HashType::Xxh3),
_ => Err("Couldn't parse the hash type (allowed: BLAKE3, CRC32, XXH3)"),
}
}
@ -267,7 +267,7 @@ fn parse_checking_method(src: &str) -> Result<CheckingMethod, &'static str> {
"name" => Ok(CheckingMethod::Name),
"size" => Ok(CheckingMethod::Size),
"hash" => Ok(CheckingMethod::Hash),
"hashmb" => Ok(CheckingMethod::HashMB),
"hashmb" => Ok(CheckingMethod::HashMb),
_ => Err("Couldn't parse the search method (allowed: NAME, SIZE, HASH, HASHMB)"),
}
}

View File

@ -48,7 +48,7 @@ pub struct FileEntry {
pub enum TypeOfFile {
Unknown = -1,
Image = 0,
ArchiveZIP,
ArchiveZip,
#[cfg(feature = "broken_audio")]
Audio,
}
@ -315,18 +315,16 @@ impl BrokenFiles {
};
for (name, file_entry) in &self.files_to_check {
#[allow(clippy::collapsible_if)]
#[allow(clippy::if_same_then_else)]
if !loaded_hash_map.contains_key(name) {
// If loaded data doesn't contains current image info
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else if file_entry.size != loaded_hash_map.get(name).unwrap().size || file_entry.modified_date != loaded_hash_map.get(name).unwrap().modified_date {
// When size or modification date of image changed, then it is clear that is different image
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else {
if file_entry.size != loaded_hash_map.get(name).unwrap().size || file_entry.modified_date != loaded_hash_map.get(name).unwrap().modified_date {
// When size or modification date of image changed, then it is clear that is different image
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else {
// Checking may be omitted when already there is entry with same size and modification date
records_already_cached.insert(name.clone(), loaded_hash_map.get(name).unwrap().clone());
}
// Checking may be omitted when already there is entry with same size and modification date
records_already_cached.insert(name.clone(), loaded_hash_map.get(name).unwrap().clone());
}
}
} else {
@ -392,7 +390,7 @@ impl BrokenFiles {
} // Something is wrong with image
}
}
TypeOfFile::ArchiveZIP => match fs::File::open(&file_entry.path) {
TypeOfFile::ArchiveZip => match fs::File::open(&file_entry.path) {
Ok(file) => match zip::ZipArchive::new(file) {
Ok(_) => Some(None),
Err(e) => {
@ -687,7 +685,7 @@ fn check_extension_avaibility(file_name_lowercase: &str) -> TypeOfFile {
if allowed_image_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
TypeOfFile::Image
} else if allowed_archive_zip_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
TypeOfFile::ArchiveZIP
TypeOfFile::ArchiveZip
} else if allowed_audio_extensions.iter().any(|e| file_name_lowercase.ends_with(e)) {
#[cfg(feature = "broken_audio")]
{

View File

@ -45,7 +45,7 @@ pub enum CheckingMethod {
Name,
Size,
Hash,
HashMB,
HashMb,
}
impl MyHasher for blake3::Hasher {
@ -78,16 +78,16 @@ impl MyHasher for xxhash_rust::xxh3::Xxh3 {
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
pub enum HashType {
Blake3,
CRC32,
XXH3,
Crc32,
Xxh3,
}
impl HashType {
fn hasher(self: &HashType) -> Box<dyn MyHasher> {
match self {
HashType::Blake3 => Box::new(blake3::Hasher::new()),
HashType::CRC32 => Box::new(crc32fast::Hasher::new()),
HashType::XXH3 => Box::new(xxhash_rust::xxh3::Xxh3::new()),
HashType::Crc32 => Box::new(crc32fast::Hasher::new()),
HashType::Xxh3 => Box::new(xxhash_rust::xxh3::Xxh3::new()),
}
}
}
@ -193,7 +193,7 @@ impl DuplicateFinder {
return;
}
}
CheckingMethod::HashMB | CheckingMethod::Hash => {
CheckingMethod::HashMb | CheckingMethod::Hash => {
if !self.check_files_size(stop_receiver, progress_sender) {
self.stopped_search = true;
return;
@ -477,7 +477,7 @@ impl DuplicateFinder {
let checking_method = self.check_method.clone();
let max_stage = match self.check_method {
CheckingMethod::Size => 0,
CheckingMethod::HashMB | CheckingMethod::Hash => 2,
CheckingMethod::HashMb | CheckingMethod::Hash => 2,
_ => 255,
};
progress_thread_handle = thread::spawn(move || loop {
@ -771,7 +771,7 @@ impl DuplicateFinder {
let mut full_hash_results: Vec<(u64, HashMap<String, Vec<FileEntry>>, Vec<String>, u64)>;
match self.check_method {
CheckingMethod::HashMB => {
CheckingMethod::HashMb => {
full_hash_results = pre_checked_map
.par_iter()
.map(|(size, vec_file_entry)| {
@ -970,7 +970,7 @@ impl DuplicateFinder {
self.information.number_of_failed_to_remove_files += tuple.2;
}
}
CheckingMethod::Hash | CheckingMethod::HashMB => {
CheckingMethod::Hash | CheckingMethod::HashMb => {
for vector_vectors in self.files_with_identical_hashes.values() {
for vector in vector_vectors.iter() {
let tuple: (u64, usize, usize) = delete_files(vector, &self.delete_method, &mut self.text_messages, self.dryrun);
@ -1129,7 +1129,7 @@ impl SaveResults for DuplicateFinder {
write!(writer, "Not found any duplicates.").unwrap();
}
}
CheckingMethod::Hash | CheckingMethod::HashMB => {
CheckingMethod::Hash | CheckingMethod::HashMb => {
if !self.files_with_identical_hashes.is_empty() {
writeln!(writer, "-------------------------------------------------Files with same hashes-------------------------------------------------").unwrap();
writeln!(
@ -1183,7 +1183,7 @@ impl PrintResults for DuplicateFinder {
println!();
}
}
CheckingMethod::Hash | CheckingMethod::HashMB => {
CheckingMethod::Hash | CheckingMethod::HashMb => {
for (_size, vector) in self.files_with_identical_hashes.iter() {
for j in vector {
number_of_files += j.len() as u64;
@ -1317,7 +1317,7 @@ fn filter_hard_links(vec_file_entry: &[FileEntry]) -> Vec<FileEntry> {
identical
}
pub fn make_hard_link(src: &PathBuf, dst: &PathBuf) -> io::Result<()> {
pub fn make_hard_link(src: &Path, dst: &Path) -> io::Result<()> {
let dst_dir = dst.parent().ok_or_else(|| Error::new(ErrorKind::Other, "No parent"))?;
let temp = tempfile::Builder::new().tempfile_in(dst_dir)?;
fs::rename(dst, temp.path())?;

View File

@ -7,7 +7,7 @@ use crossbeam_channel::Receiver;
use std::collections::BTreeMap;
use std::fs::{File, Metadata};
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread::sleep;
@ -288,7 +288,7 @@ impl EmptyFolder {
}
}
fn set_as_not_empty_folder(folders_checked: &mut BTreeMap<PathBuf, FolderEntry>, current_folder: &PathBuf) {
fn set_as_not_empty_folder(folders_checked: &mut BTreeMap<PathBuf, FolderEntry>, current_folder: &Path) {
// Not folder so it may be a file or symbolic link so it isn't empty
folders_checked.get_mut(current_folder).unwrap().is_empty = FolderEmptiness::No;
let mut d = folders_checked.get_mut(current_folder).unwrap();

View File

@ -339,18 +339,16 @@ impl SimilarImages {
};
for (name, file_entry) in &self.images_to_check {
#[allow(clippy::collapsible_if)]
#[allow(clippy::if_same_then_else)]
if !loaded_hash_map.contains_key(name) {
// If loaded data doesn't contains current image info
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else if file_entry.size != loaded_hash_map.get(name).unwrap().size || file_entry.modified_date != loaded_hash_map.get(name).unwrap().modified_date {
// When size or modification date of image changed, then it is clear that is different image
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else {
if file_entry.size != loaded_hash_map.get(name).unwrap().size || file_entry.modified_date != loaded_hash_map.get(name).unwrap().modified_date {
// When size or modification date of image changed, then it is clear that is different image
non_cached_files_to_check.insert(name.clone(), file_entry.clone());
} else {
// Checking may be omitted when already there is entry with same size and modification date
records_already_cached.insert(name.clone(), loaded_hash_map.get(name).unwrap().clone());
}
// Checking may be omitted when already there is entry with same size and modification date
records_already_cached.insert(name.clone(), loaded_hash_map.get(name).unwrap().clone());
}
}
} else {

View File

@ -137,7 +137,7 @@ pub fn connect_button_search(
} else if radio_button_duplicates_size.get_active() {
check_method = duplicate::CheckingMethod::Size;
} else if radio_button_duplicates_hashmb.get_active() {
check_method = duplicate::CheckingMethod::HashMB;
check_method = duplicate::CheckingMethod::HashMb;
} else if radio_button_duplicates_hash.get_active() {
check_method = duplicate::CheckingMethod::Hash;
} else {
@ -149,9 +149,9 @@ pub fn connect_button_search(
if radio_button_hash_type_blake3.get_active() {
hash_type = duplicate::HashType::Blake3;
} else if radio_button_hash_type_crc32.get_active() {
hash_type = duplicate::HashType::CRC32;
hash_type = duplicate::HashType::Crc32;
} else if radio_button_hash_type_xxh3.get_active() {
hash_type = duplicate::HashType::XXH3;
hash_type = duplicate::HashType::Xxh3;
} else {
panic!("No radio button is pressed");
}

View File

@ -70,7 +70,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
duplicates_group = information.number_of_groups_by_name;
entry_info.set_text(format!("Found {} files in {} groups which have same names.", duplicates_number, duplicates_group).as_str());
}
CheckingMethod::Hash | CheckingMethod::HashMB => {
CheckingMethod::Hash | CheckingMethod::HashMb => {
duplicates_number = information.number_of_duplicated_files_by_hash;
duplicates_size = information.lost_space_by_hash;
duplicates_group = information.number_of_groups_by_hash;
@ -132,7 +132,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
}
}
}
CheckingMethod::Hash | CheckingMethod::HashMB => {
CheckingMethod::Hash | CheckingMethod::HashMb => {
let btreemap = df.get_files_sorted_by_hash();
for (size, vectors_vector) in btreemap.iter().rev() {

View File

@ -66,7 +66,7 @@ fn popover_all_except_oldest(popover: &gtk::Popover, tree_view: &gtk::TreeView,
let mut tree_iter_array: Vec<TreeIter> = Vec::new();
let mut oldest_index: Option<usize> = None;
let mut current_index: usize = 0;
let mut oldest_modification_time: u64 = u64::max_value();
let mut oldest_modification_time: u64 = u64::MAX;
let mut file_length: usize = 0;
@ -182,7 +182,7 @@ fn popover_one_oldest(popover: &gtk::Popover, tree_view: &gtk::TreeView, column_
let mut tree_iter_array: Vec<TreeIter> = Vec::new();
let mut oldest_index: Option<usize> = None;
let mut current_index: usize = 0;
let mut oldest_modification_time: u64 = u64::max_value();
let mut oldest_modification_time: u64 = u64::MAX;
let mut file_length: usize = 0;
@ -294,7 +294,7 @@ fn popover_select_custom(popover: &gtk::Popover, gui_data: &GuiData, tree_view:
Path,
Name,
PathName,
};
}
let wildcard_type: WildcardType;
// Accept Dialog
@ -410,7 +410,7 @@ fn popover_unselect_custom(popover: &gtk::Popover, gui_data: &GuiData, tree_view
Path,
Name,
PathName,
};
}
let wildcard_type: WildcardType;
// Accept Dialog
@ -590,8 +590,8 @@ fn popover_all_except_smallest(popover: &gtk::Popover, tree_view: &gtk::TreeView
let mut tree_iter_array: Vec<TreeIter> = Vec::new();
let mut smallest_index: Option<usize> = None;
let mut current_index: usize = 0;
let mut smallest_size_as_bytes: u64 = u64::max_value();
let mut smallest_number_of_pixels: u64 = u64::max_value();
let mut smallest_size_as_bytes: u64 = u64::MAX;
let mut smallest_number_of_pixels: u64 = u64::MAX;
loop {
let color = tree_model.get_value(&tree_iter_all, column_color).get::<String>().unwrap().unwrap();

View File

@ -32,7 +32,7 @@ pub fn connect_progress_window(
let future = async move {
while let Some(item) = futures_receiver_duplicate_files.next().await {
match item.checking_method {
duplicate::CheckingMethod::Hash | duplicate::CheckingMethod::HashMB => {
duplicate::CheckingMethod::Hash | duplicate::CheckingMethod::HashMb => {
label_stage.show();
match item.current_stage {
// Checking Size

View File

@ -1,7 +1,7 @@
use gtk::prelude::*;
#[derive(Clone)]
pub struct GUIAbout {
pub struct GuiAbout {
pub about_dialog: gtk::AboutDialog,
pub button_repository: gtk::Button,
@ -9,7 +9,7 @@ pub struct GUIAbout {
pub button_instruction: gtk::Button,
}
impl GUIAbout {
impl GuiAbout {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let about_dialog: gtk::AboutDialog = builder.get_object("about_dialog").unwrap();

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use gtk::Button;
#[derive(Clone)]
pub struct GUIBottomButtons {
pub struct GuiBottomButtons {
pub buttons_search: gtk::Button,
pub buttons_select: gtk::Button,
pub buttons_delete: gtk::Button,
@ -14,7 +14,7 @@ pub struct GUIBottomButtons {
pub buttons_array: [Button; 6],
}
impl GUIBottomButtons {
impl GuiBottomButtons {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let buttons_search: gtk::Button = builder.get_object("buttons_search").unwrap();
let buttons_select: gtk::Button = builder.get_object("buttons_select").unwrap();

View File

@ -1,12 +1,12 @@
extern crate gtk;
use crate::gui_about::GUIAbout;
use crate::gui_bottom_buttons::GUIBottomButtons;
use crate::gui_header::GUIHeader;
use crate::gui_main_notebook::GUIMainNotebook;
use crate::gui_popovers::GUIPopovers;
use crate::gui_progress_dialog::GUIProgressDialog;
use crate::gui_settings::GUISettings;
use crate::gui_upper_notepad::GUIUpperNotebook;
use crate::gui_about::GuiAbout;
use crate::gui_bottom_buttons::GuiBottomButtons;
use crate::gui_header::GuiHeader;
use crate::gui_main_notebook::GuiMainNotebook;
use crate::gui_popovers::GuiPopovers;
use crate::gui_progress_dialog::GuiProgressDialog;
use crate::gui_settings::GuiSettings;
use crate::gui_upper_notepad::GuiUpperNotebook;
use crate::notebook_enums::*;
use crate::taskbar_progress::TaskbarProgress;
use crossbeam_channel::unbounded;
@ -35,14 +35,14 @@ pub struct GuiData {
// Windows
pub window_main: gtk::Window,
pub main_notebook: GUIMainNotebook,
pub upper_notebook: GUIUpperNotebook,
pub popovers: GUIPopovers,
pub bottom_buttons: GUIBottomButtons,
pub progress_window: GUIProgressDialog,
pub about: GUIAbout,
pub settings: GUISettings,
pub header: GUIHeader,
pub main_notebook: GuiMainNotebook,
pub upper_notebook: GuiUpperNotebook,
pub popovers: GuiPopovers,
pub bottom_buttons: GuiBottomButtons,
pub progress_window: GuiProgressDialog,
pub about: GuiAbout,
pub settings: GuiSettings,
pub header: GuiHeader,
// Taskbar state
pub taskbar_state: Rc<RefCell<TaskbarProgress>>,
@ -88,14 +88,14 @@ impl GuiData {
window_main.show_all();
window_main.set_title("Czkawka");
let main_notebook = GUIMainNotebook::create_from_builder(&builder);
let upper_notebook = GUIUpperNotebook::create_from_builder(&builder);
let popovers = GUIPopovers::create_from_builder(&builder);
let bottom_buttons = GUIBottomButtons::create_from_builder(&builder);
let progress_window = GUIProgressDialog::create_from_builder(&builder);
let about = GUIAbout::create_from_builder(&builder);
let header = GUIHeader::create_from_builder(&builder);
let settings = GUISettings::create_from_builder(&builder);
let main_notebook = GuiMainNotebook::create_from_builder(&builder);
let upper_notebook = GuiUpperNotebook::create_from_builder(&builder);
let popovers = GuiPopovers::create_from_builder(&builder);
let bottom_buttons = GuiBottomButtons::create_from_builder(&builder);
let progress_window = GuiProgressDialog::create_from_builder(&builder);
let about = GuiAbout::create_from_builder(&builder);
let header = GuiHeader::create_from_builder(&builder);
let settings = GuiSettings::create_from_builder(&builder);
////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,12 +1,12 @@
use gtk::prelude::*;
#[derive(Clone)]
pub struct GUIHeader {
pub struct GuiHeader {
pub button_settings: gtk::Button,
pub button_app_info: gtk::Button,
}
impl GUIHeader {
impl GuiHeader {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let button_settings: gtk::Button = builder.get_object("button_settings").unwrap();
let button_app_info: gtk::Button = builder.get_object("button_app_info").unwrap();

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use gtk::TreeView;
#[derive(Clone)]
pub struct GUIMainNotebook {
pub struct GuiMainNotebook {
pub notebook_main: gtk::Notebook,
pub scrolled_window_duplicate_finder: gtk::ScrolledWindow,
@ -60,7 +60,7 @@ pub struct GUIMainNotebook {
pub image_preview_similar_images: gtk::Image,
}
impl GUIMainNotebook {
impl GuiMainNotebook {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let notebook_main: gtk::Notebook = builder.get_object("notebook_main").unwrap();

View File

@ -1,7 +1,7 @@
use gtk::prelude::*;
#[derive(Clone)]
pub struct GUIPopovers {
pub struct GuiPopovers {
pub buttons_popover_select_all: gtk::Button,
pub buttons_popover_unselect_all: gtk::Button,
pub buttons_popover_reverse: gtk::Button,
@ -26,7 +26,7 @@ pub struct GUIPopovers {
pub popover_right_click: gtk::Popover,
}
impl GUIPopovers {
impl GuiPopovers {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let buttons_popover_select_all: gtk::Button = builder.get_object("buttons_popover_select_all").unwrap();
let buttons_popover_unselect_all: gtk::Button = builder.get_object("buttons_popover_unselect_all").unwrap();

View File

@ -1,7 +1,7 @@
use gtk::prelude::*;
#[derive(Clone)]
pub struct GUIProgressDialog {
pub struct GuiProgressDialog {
pub window_progress: gtk::Window,
pub progress_bar_current_stage: gtk::ProgressBar,
@ -14,7 +14,7 @@ pub struct GUIProgressDialog {
pub button_stop_in_dialog: gtk::Button,
}
impl GUIProgressDialog {
impl GuiProgressDialog {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let window_progress: gtk::Window = builder.get_object("window_progress").unwrap();

View File

@ -1,7 +1,7 @@
use gtk::prelude::*;
#[derive(Clone)]
pub struct GUISettings {
pub struct GuiSettings {
pub window_settings: gtk::Window,
// General
@ -25,7 +25,7 @@ pub struct GUISettings {
pub button_settings_reset_configuration: gtk::Button,
}
impl GUISettings {
impl GuiSettings {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let window_settings: gtk::Window = builder.get_object("window_settings").unwrap();
@ -56,13 +56,13 @@ impl GUISettings {
check_button_settings_confirm_deletion,
check_button_settings_confirm_group_deletion,
check_button_settings_show_text_view,
check_button_settings_use_cache,
check_button_settings_use_trash,
check_button_settings_hide_hard_links,
check_button_settings_show_preview_similar_images,
button_settings_save_configuration,
button_settings_load_configuration,
button_settings_reset_configuration,
check_button_settings_show_preview_similar_images,
check_button_settings_hide_hard_links,
check_button_settings_use_cache,
check_button_settings_use_trash,
}
}
}

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use gtk::TreeView;
#[derive(Clone)]
pub struct GUIUpperNotebook {
pub struct GuiUpperNotebook {
pub notebook_upper: gtk::Notebook,
pub scrolled_window_included_directories: gtk::ScrolledWindow,
@ -24,7 +24,7 @@ pub struct GUIUpperNotebook {
pub buttons_remove_excluded_directory: gtk::Button,
}
impl GUIUpperNotebook {
impl GuiUpperNotebook {
pub fn create_from_builder(builder: &gtk::Builder) -> Self {
let notebook_upper: gtk::Notebook = builder.get_object("notebook_upper").unwrap();

View File

@ -37,8 +37,7 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
add_text_to_text_view(&text_view_errors, format!("Failed configuration to create configuration folder {}", config_dir.display()).as_str());
return;
}
let mut data_to_save: Vec<String> = Vec::new();
let mut data_to_save: Vec<String> = Vec::with_capacity(16);
//// Included Directories
data_to_save.push("--included_directories:".to_string());

View File

@ -1,3 +1,4 @@
#![allow(clippy::upper_case_acronyms)]
#![cfg(not(target_os = "windows"))]
use std::convert::From;