Cargo clippy

This commit is contained in:
ChristianVisintin
2021-01-16 18:02:12 +01:00
parent ac02928e69
commit 23ca2baa8c
8 changed files with 29 additions and 38 deletions

View File

@@ -27,7 +27,7 @@ use std::path::PathBuf;
// Deps
use crate::filetransfer::FileTransferProtocol;
use crate::host::Localhost;
use crate::host::{HostError, Localhost};
use crate::ui::activities::{
auth_activity::AuthActivity, filetransfer_activity::FileTransferActivity,
filetransfer_activity::FileTransferParams, setup_activity::SetupActivity, Activity,
@@ -60,11 +60,11 @@ impl ActivityManager {
/// ### new
///
/// Initializes a new Activity Manager
pub fn new(local_dir: &PathBuf, interval: Duration) -> Result<ActivityManager, ()> {
pub fn new(local_dir: &PathBuf, interval: Duration) -> Result<ActivityManager, HostError> {
// Prepare Context
let host: Localhost = match Localhost::new(local_dir.clone()) {
Ok(h) => h,
Err(_) => return Err(()),
Err(e) => return Err(e),
};
let ctx: Context = Context::new(host);
Ok(ActivityManager {

View File

@@ -180,10 +180,12 @@ impl FtpFileTransfer {
Err(_) => None,
};
// Get filesize
let filesize: usize = match metadata.get(6).unwrap().as_str().parse::<usize>() {
Ok(sz) => sz,
Err(_) => 0,
};
let filesize: usize = metadata
.get(6)
.unwrap()
.as_str()
.parse::<usize>()
.unwrap_or(0);
let file_name: String = String::from(metadata.get(8).unwrap().as_str());
// Check if file_name is '.' or '..'
if file_name.as_str() == "." || file_name.as_str() == ".." {
@@ -270,10 +272,7 @@ impl FtpFileTransfer {
true => 0, // If is directory, filesize is 0
false => match metadata.get(3) {
// If is file, parse arg 3
Some(val) => match val.as_str().parse::<usize>() {
Ok(sz) => sz,
Err(_) => 0,
},
Some(val) => val.as_str().parse::<usize>().unwrap_or(0),
None => 0, // Should not happen
},
};

View File

@@ -167,10 +167,7 @@ impl ScpFileTransfer {
Err(_) => None,
};
// Get filesize
let filesize: usize = match metadata.get(6).unwrap().as_str().parse::<usize>() {
Ok(sz) => sz,
Err(_) => 0,
};
let filesize: usize = metadata.get(6).unwrap().as_str().parse::<usize>().unwrap_or(0);
// Get link and name
let (file_name, symlink_path): (String, Option<PathBuf>) = match is_symlink {
true => self.get_name_and_link(metadata.get(8).unwrap().as_str()),

View File

@@ -30,6 +30,7 @@ extern crate bitflags;
// Locals
use super::FsEntry;
// Ext
use std::cmp::Reverse;
use std::collections::VecDeque;
use std::path::{Path, PathBuf};
use std::str::FromStr;
@@ -238,16 +239,14 @@ impl FileExplorer {
///
/// Sort files by creation time; the newest comes first
fn sort_files_by_creation_time(&mut self) {
self.files
.sort_by(|a: &FsEntry, b: &FsEntry| b.get_creation_time().cmp(&a.get_creation_time()));
self.files.sort_by_key(|b: &FsEntry| Reverse(b.get_creation_time()));
}
/// ### sort_files_by_size
///
/// Sort files by size
fn sort_files_by_size(&mut self) {
self.files
.sort_by(|a: &FsEntry, b: &FsEntry| b.get_size().cmp(&a.get_size()));
self.files.sort_by_key(|b: &FsEntry| Reverse(b.get_size()));
}
/// ### sort_files_directories_first

View File

@@ -167,8 +167,8 @@ fn main() {
// Create activity manager (and context too)
let mut manager: ActivityManager = match ActivityManager::new(&wrkdir, ticks) {
Ok(m) => m,
Err(_) => {
eprintln!("Invalid directory '{}'", wrkdir.display());
Err(err) => {
eprintln!("Could not start activity manager: {}", err);
std::process::exit(255);
}
};

View File

@@ -369,6 +369,7 @@ impl BookmarksClient {
}
#[cfg(test)]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
mod tests {
use super::*;
@@ -376,7 +377,7 @@ mod tests {
use std::time::Duration;
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_new() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -409,7 +410,7 @@ mod tests {
}
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_new_from_existing() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -455,7 +456,7 @@ mod tests {
}
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_manipulate_bookmarks() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -501,7 +502,7 @@ mod tests {
#[test]
#[should_panic]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_bad_bookmark_name() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -520,7 +521,7 @@ mod tests {
}
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_manipulate_recents() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -555,7 +556,7 @@ mod tests {
}
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_dup_recent() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -580,7 +581,7 @@ mod tests {
}
#[test]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_recents_more_than_limit() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -628,7 +629,7 @@ mod tests {
#[test]
#[should_panic]
#[cfg(not(target_os = "macos"))] // CI/CD blocks
fn test_system_bookmarks_add_bookmark_empty() {
let tmp_dir: tempfile::TempDir = create_tmp_dir();
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
@@ -649,6 +650,7 @@ mod tests {
/// ### get_paths
///
/// Get paths for configuration and key for bookmarks
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
let k: PathBuf = PathBuf::from(dir);
let mut c: PathBuf = k.clone();
@@ -659,6 +661,7 @@ mod tests {
/// ### create_tmp_dir
///
/// Create temporary directory
fn create_tmp_dir() -> tempfile::TempDir {
tempfile::TempDir::new().ok().unwrap()
}

View File

@@ -97,7 +97,7 @@ impl KeyStorage for FileStorage {
{
Ok(mut file) => {
// Write key to file
if let Err(_) = file.write_all(key.as_bytes()) {
if file.write_all(key.as_bytes()).is_err() {
return Err(KeyStorageError::ProviderError);
}
// Set file to readonly

View File

@@ -89,14 +89,7 @@ impl KeyStorage for KeyringStorage {
// Check what kind of error is returned
match storage.get_password() {
Ok(_) => true,
Err(err) => match err {
KeyringError::NoBackendFound => false,
//#[cfg(target_os = "macos")]
//KeyringError::MacOsKeychainError(_) => false,
//#[cfg(target_os = "windows")]
//KeyringError::WindowsVaultError => false,
_ => true,
},
Err(err) => !matches!(err, KeyringError::NoBackendFound),
}
}
}