mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Cargo clippy
This commit is contained in:
@@ -27,7 +27,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
// Deps
|
// Deps
|
||||||
use crate::filetransfer::FileTransferProtocol;
|
use crate::filetransfer::FileTransferProtocol;
|
||||||
use crate::host::Localhost;
|
use crate::host::{HostError, Localhost};
|
||||||
use crate::ui::activities::{
|
use crate::ui::activities::{
|
||||||
auth_activity::AuthActivity, filetransfer_activity::FileTransferActivity,
|
auth_activity::AuthActivity, filetransfer_activity::FileTransferActivity,
|
||||||
filetransfer_activity::FileTransferParams, setup_activity::SetupActivity, Activity,
|
filetransfer_activity::FileTransferParams, setup_activity::SetupActivity, Activity,
|
||||||
@@ -60,11 +60,11 @@ impl ActivityManager {
|
|||||||
/// ### new
|
/// ### new
|
||||||
///
|
///
|
||||||
/// Initializes a new Activity Manager
|
/// 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
|
// Prepare Context
|
||||||
let host: Localhost = match Localhost::new(local_dir.clone()) {
|
let host: Localhost = match Localhost::new(local_dir.clone()) {
|
||||||
Ok(h) => h,
|
Ok(h) => h,
|
||||||
Err(_) => return Err(()),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
let ctx: Context = Context::new(host);
|
let ctx: Context = Context::new(host);
|
||||||
Ok(ActivityManager {
|
Ok(ActivityManager {
|
||||||
|
|||||||
@@ -180,10 +180,12 @@ impl FtpFileTransfer {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
};
|
};
|
||||||
// Get filesize
|
// Get filesize
|
||||||
let filesize: usize = match metadata.get(6).unwrap().as_str().parse::<usize>() {
|
let filesize: usize = metadata
|
||||||
Ok(sz) => sz,
|
.get(6)
|
||||||
Err(_) => 0,
|
.unwrap()
|
||||||
};
|
.as_str()
|
||||||
|
.parse::<usize>()
|
||||||
|
.unwrap_or(0);
|
||||||
let file_name: String = String::from(metadata.get(8).unwrap().as_str());
|
let file_name: String = String::from(metadata.get(8).unwrap().as_str());
|
||||||
// Check if file_name is '.' or '..'
|
// Check if file_name is '.' or '..'
|
||||||
if file_name.as_str() == "." || file_name.as_str() == ".." {
|
if file_name.as_str() == "." || file_name.as_str() == ".." {
|
||||||
@@ -270,10 +272,7 @@ impl FtpFileTransfer {
|
|||||||
true => 0, // If is directory, filesize is 0
|
true => 0, // If is directory, filesize is 0
|
||||||
false => match metadata.get(3) {
|
false => match metadata.get(3) {
|
||||||
// If is file, parse arg 3
|
// If is file, parse arg 3
|
||||||
Some(val) => match val.as_str().parse::<usize>() {
|
Some(val) => val.as_str().parse::<usize>().unwrap_or(0),
|
||||||
Ok(sz) => sz,
|
|
||||||
Err(_) => 0,
|
|
||||||
},
|
|
||||||
None => 0, // Should not happen
|
None => 0, // Should not happen
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -167,10 +167,7 @@ impl ScpFileTransfer {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
};
|
};
|
||||||
// Get filesize
|
// Get filesize
|
||||||
let filesize: usize = match metadata.get(6).unwrap().as_str().parse::<usize>() {
|
let filesize: usize = metadata.get(6).unwrap().as_str().parse::<usize>().unwrap_or(0);
|
||||||
Ok(sz) => sz,
|
|
||||||
Err(_) => 0,
|
|
||||||
};
|
|
||||||
// Get link and name
|
// Get link and name
|
||||||
let (file_name, symlink_path): (String, Option<PathBuf>) = match is_symlink {
|
let (file_name, symlink_path): (String, Option<PathBuf>) = match is_symlink {
|
||||||
true => self.get_name_and_link(metadata.get(8).unwrap().as_str()),
|
true => self.get_name_and_link(metadata.get(8).unwrap().as_str()),
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ extern crate bitflags;
|
|||||||
// Locals
|
// Locals
|
||||||
use super::FsEntry;
|
use super::FsEntry;
|
||||||
// Ext
|
// Ext
|
||||||
|
use std::cmp::Reverse;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -238,16 +239,14 @@ impl FileExplorer {
|
|||||||
///
|
///
|
||||||
/// Sort files by creation time; the newest comes first
|
/// Sort files by creation time; the newest comes first
|
||||||
fn sort_files_by_creation_time(&mut self) {
|
fn sort_files_by_creation_time(&mut self) {
|
||||||
self.files
|
self.files.sort_by_key(|b: &FsEntry| Reverse(b.get_creation_time()));
|
||||||
.sort_by(|a: &FsEntry, b: &FsEntry| b.get_creation_time().cmp(&a.get_creation_time()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### sort_files_by_size
|
/// ### sort_files_by_size
|
||||||
///
|
///
|
||||||
/// Sort files by size
|
/// Sort files by size
|
||||||
fn sort_files_by_size(&mut self) {
|
fn sort_files_by_size(&mut self) {
|
||||||
self.files
|
self.files.sort_by_key(|b: &FsEntry| Reverse(b.get_size()));
|
||||||
.sort_by(|a: &FsEntry, b: &FsEntry| b.get_size().cmp(&a.get_size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### sort_files_directories_first
|
/// ### sort_files_directories_first
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ fn main() {
|
|||||||
// Create activity manager (and context too)
|
// Create activity manager (and context too)
|
||||||
let mut manager: ActivityManager = match ActivityManager::new(&wrkdir, ticks) {
|
let mut manager: ActivityManager = match ActivityManager::new(&wrkdir, ticks) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(_) => {
|
Err(err) => {
|
||||||
eprintln!("Invalid directory '{}'", wrkdir.display());
|
eprintln!("Could not start activity manager: {}", err);
|
||||||
std::process::exit(255);
|
std::process::exit(255);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ impl BookmarksClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -376,7 +377,7 @@ mod tests {
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_new() {
|
fn test_system_bookmarks_new() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -409,7 +410,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_new_from_existing() {
|
fn test_system_bookmarks_new_from_existing() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -455,7 +456,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_manipulate_bookmarks() {
|
fn test_system_bookmarks_manipulate_bookmarks() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -501,7 +502,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_bad_bookmark_name() {
|
fn test_system_bookmarks_bad_bookmark_name() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -520,7 +521,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_manipulate_recents() {
|
fn test_system_bookmarks_manipulate_recents() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -555,7 +556,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_dup_recent() {
|
fn test_system_bookmarks_dup_recent() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -580,7 +581,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_recents_more_than_limit() {
|
fn test_system_bookmarks_recents_more_than_limit() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -628,7 +629,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
#[cfg(not(target_os = "macos"))] // CI/CD blocks
|
|
||||||
fn test_system_bookmarks_add_bookmark_empty() {
|
fn test_system_bookmarks_add_bookmark_empty() {
|
||||||
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
@@ -649,6 +650,7 @@ mod tests {
|
|||||||
/// ### get_paths
|
/// ### get_paths
|
||||||
///
|
///
|
||||||
/// Get paths for configuration and key for bookmarks
|
/// Get paths for configuration and key for bookmarks
|
||||||
|
|
||||||
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
||||||
let k: PathBuf = PathBuf::from(dir);
|
let k: PathBuf = PathBuf::from(dir);
|
||||||
let mut c: PathBuf = k.clone();
|
let mut c: PathBuf = k.clone();
|
||||||
@@ -659,6 +661,7 @@ mod tests {
|
|||||||
/// ### create_tmp_dir
|
/// ### create_tmp_dir
|
||||||
///
|
///
|
||||||
/// Create temporary directory
|
/// Create temporary directory
|
||||||
|
|
||||||
fn create_tmp_dir() -> tempfile::TempDir {
|
fn create_tmp_dir() -> tempfile::TempDir {
|
||||||
tempfile::TempDir::new().ok().unwrap()
|
tempfile::TempDir::new().ok().unwrap()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ impl KeyStorage for FileStorage {
|
|||||||
{
|
{
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
// Write key to 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);
|
return Err(KeyStorageError::ProviderError);
|
||||||
}
|
}
|
||||||
// Set file to readonly
|
// Set file to readonly
|
||||||
|
|||||||
@@ -89,14 +89,7 @@ impl KeyStorage for KeyringStorage {
|
|||||||
// Check what kind of error is returned
|
// Check what kind of error is returned
|
||||||
match storage.get_password() {
|
match storage.get_password() {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(err) => match err {
|
Err(err) => !matches!(err, KeyringError::NoBackendFound),
|
||||||
KeyringError::NoBackendFound => false,
|
|
||||||
//#[cfg(target_os = "macos")]
|
|
||||||
//KeyringError::MacOsKeychainError(_) => false,
|
|
||||||
//#[cfg(target_os = "windows")]
|
|
||||||
//KeyringError::WindowsVaultError => false,
|
|
||||||
_ => true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user