This commit is contained in:
veeso
2023-02-09 17:20:48 +01:00
parent 62003308a7
commit 4d5f3a6b63
40 changed files with 139 additions and 147 deletions

View File

@@ -78,7 +78,7 @@ impl ActivityManager {
params.set_default_secret(password.to_string());
} else {
match tty::read_secret_from_tty("Password: ") {
Err(err) => return Err(format!("Could not read password: {}", err)),
Err(err) => return Err(format!("Could not read password: {err}")),
Ok(Some(secret)) => {
debug!(
"Read password from tty: {}",
@@ -105,8 +105,7 @@ impl ActivityManager {
if let Some(bookmarks_client) = self.context.as_mut().unwrap().bookmarks_client_mut() {
match bookmarks_client.get_bookmark(bookmark_name) {
None => Err(format!(
r#"Could not resolve bookmark name: "{}" no such bookmark"#,
bookmark_name
r#"Could not resolve bookmark name: "{bookmark_name}" no such bookmark"#
)),
Some(params) => self.set_filetransfer_params(params, password),
}
@@ -217,7 +216,7 @@ impl ActivityManager {
Err(err) => {
// Set error in context
error!("Failed to initialize localhost: {}", err);
ctx.set_error(format!("Could not initialize localhost: {}", err));
ctx.set_error(format!("Could not initialize localhost: {err}"));
return None;
}
};
@@ -325,7 +324,7 @@ impl ActivityManager {
environment::get_config_paths(config_dir.as_path());
match ConfigClient::new(config_path.as_path(), ssh_dir.as_path()) {
Ok(cli) => Ok(cli),
Err(err) => Err(format!("Could not read configuration: {}", err)),
Err(err) => Err(format!("Could not read configuration: {err}")),
}
}
None => Err(String::from(
@@ -334,8 +333,7 @@ impl ActivityManager {
}
}
Err(err) => Err(format!(
"Could not initialize configuration directory: {}",
err
"Could not initialize configuration directory: {err}"
)),
}
}

View File

@@ -127,12 +127,12 @@ mod tests {
fn test_config_serialization_errors() {
let error: SerializerError = SerializerError::new(SerializerErrorKind::Syntax);
assert!(error.msg.is_none());
assert_eq!(format!("{}", error), String::from("Syntax error"));
assert_eq!(format!("{error}"), String::from("Syntax error"));
let error: SerializerError =
SerializerError::new_ex(SerializerErrorKind::Syntax, String::from("bad syntax"));
assert!(error.msg.is_some());
assert_eq!(
format!("{}", error),
format!("{error}"),
String::from("Syntax error (bad syntax)")
);
// Fmt
@@ -159,7 +159,7 @@ mod tests {
fn test_config_serialization_params_deserialize_ok() {
let toml_file: tempfile::NamedTempFile = create_good_toml_bookmarks_params();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
// Parse
let cfg = deserialize(Box::new(toml_file));
assert!(cfg.is_ok());
@@ -209,7 +209,7 @@ mod tests {
fn test_config_serialization_params_deserialize_ok_no_opts() {
let toml_file: tempfile::NamedTempFile = create_good_toml_bookmarks_params_no_opts();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
// Parse
let cfg = deserialize(Box::new(toml_file));
assert!(cfg.is_ok());
@@ -249,7 +249,7 @@ mod tests {
fn test_config_serialization_params_deserialize_nok() {
let toml_file: tempfile::NamedTempFile = create_bad_toml_bookmarks_params();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
// Parse
assert!(deserialize::<UserConfig>(Box::new(toml_file)).is_err());
}
@@ -268,7 +268,7 @@ mod tests {
assert!(serialize(&cfg, writer).is_ok());
// Reload configuration and check if it's ok
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
assert!(deserialize::<UserConfig>(Box::new(toml_file)).is_ok());
}
@@ -353,7 +353,7 @@ mod tests {
fn test_config_serializer_bookmarks_serializer_deserialize_ok() {
let toml_file: tempfile::NamedTempFile = create_good_toml_bookmarks();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
// Parse
let hosts = deserialize(Box::new(toml_file));
assert!(hosts.is_ok());
@@ -412,7 +412,7 @@ mod tests {
fn test_config_serializer_bookmarks_serializer_deserialize_nok() {
let toml_file: tempfile::NamedTempFile = create_bad_toml_bookmarks();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
// Parse
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
}
@@ -500,11 +500,11 @@ mod tests {
fn test_config_serialization_theme_deserialize() {
let toml_file = create_good_toml_theme();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
assert!(deserialize::<Theme>(Box::new(toml_file)).is_ok());
let toml_file = create_bad_toml_theme();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().seek(SeekFrom::Start(0)).unwrap();
toml_file.as_file().rewind().unwrap();
assert!(deserialize::<Theme>(Box::new(toml_file)).is_err());
}

View File

@@ -287,7 +287,7 @@ impl Formatter {
name.push('/');
}
// Add to cur str, prefix and the key value
format!("{}{}{:0width$}", cur_str, prefix, name, width = file_len)
format!("{cur_str}{prefix}{name:0file_len$}")
}
/// Format path
@@ -347,7 +347,7 @@ impl Formatter {
),
}
// Add to cur str, prefix and the key value
format!("{}{}{:10}", cur_str, prefix, pex)
format!("{cur_str}{prefix}{pex:10}")
}
/// Format file size
@@ -363,7 +363,7 @@ impl Formatter {
// Get byte size
let size: ByteSize = ByteSize(fsentry.metadata().size);
// Add to cur str, prefix and the key value
format!("{}{}{:10}", cur_str, prefix, size)
format!("{cur_str}{prefix}{size:10}")
} else if fsentry.metadata().symlink.is_some() {
let size = ByteSize(
fsentry
@@ -374,10 +374,10 @@ impl Formatter {
.to_string_lossy()
.len() as u64,
);
format!("{}{}{:10}", cur_str, prefix, size)
format!("{cur_str}{prefix}{size:10}")
} else {
// Add to cur str, prefix and the key value
format!("{}{} ", cur_str, prefix)
format!("{cur_str}{prefix} ")
}
}
@@ -397,7 +397,7 @@ impl Formatter {
};
// Replace `FMT_KEY_NAME` with name
match fsentry.metadata().symlink.as_deref() {
None => format!("{}{} ", cur_str, prefix),
None => format!("{cur_str}{prefix} "),
Some(p) => format!(
"{}{}-> {:0width$}",
cur_str,
@@ -432,7 +432,7 @@ impl Formatter {
None => 0.to_string(),
};
// Add to cur str, prefix and the key value
format!("{}{}{:12}", cur_str, prefix, username)
format!("{cur_str}{prefix}{username:12}")
}
/// Fallback function in case the format key is unknown
@@ -446,7 +446,7 @@ impl Formatter {
_fmt_extra: Option<&String>,
) -> String {
// Add to cur str and prefix
format!("{}{}", cur_str, prefix)
format!("{cur_str}{prefix}")
}
// Static
@@ -1008,6 +1008,6 @@ mod tests {
_fmt_len: Option<&usize>,
_fmt_extra: Option<&String>,
) -> String {
format!("{}{}A", cur_str, prefix)
format!("{cur_str}{prefix}A")
}
}

View File

@@ -41,8 +41,7 @@ impl Builder {
(protocol, params) => {
error!("Invalid params for protocol '{:?}'", protocol);
panic!(
"Invalid protocol '{:?}' with parameters of type {:?}",
protocol, params
"Invalid protocol '{protocol:?}' with parameters of type {params:?}"
)
}
}

View File

@@ -1099,7 +1099,7 @@ mod tests {
Path::new("/tmp"),
);
assert_eq!(
format!("{}", err),
format!("{err}"),
String::from("Could not create file: address in use (/tmp)"),
);
assert_eq!(

View File

@@ -42,13 +42,13 @@ fn main() {
let run_opts: RunOpts = match parse_args(args) {
Ok(opts) => opts,
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
std::process::exit(255);
}
};
// Setup logging
if let Err(err) = logging::init(run_opts.log_level) {
eprintln!("Failed to initialize logging: {}", err);
eprintln!("Failed to initialize logging: {err}");
}
info!("termscp {} started!", TERMSCP_VERSION);
// Run
@@ -67,8 +67,7 @@ fn parse_args(args: Args) -> Result<RunOpts, String> {
// Version
if args.version {
return Err(format!(
"termscp - {} - Developed by {}",
TERMSCP_VERSION, TERMSCP_AUTHORS,
"termscp - {TERMSCP_VERSION} - Developed by {TERMSCP_AUTHORS}",
));
}
// Setup activity?
@@ -108,7 +107,7 @@ fn parse_args(args: Args) -> Result<RunOpts, String> {
// Change working directory if local dir is set
let localdir: PathBuf = PathBuf::from(localdir);
if let Err(err) = env::set_current_dir(localdir.as_path()) {
return Err(format!("Bad working directory argument: {}", err));
return Err(format!("Bad working directory argument: {err}"));
}
}
Ok(run_opts)
@@ -134,7 +133,7 @@ fn parse_address_arg(args: &Args) -> Result<Remote, String> {
/// Parse remote address
fn parse_remote_address(remote: &str) -> Result<FileTransferParams, String> {
utils::parser::parse_remote_opt(remote).map_err(|e| format!("Bad address option: {}", e))
utils::parser::parse_remote_opt(remote).map_err(|e| format!("Bad address option: {e}"))
}
/// ### run
@@ -148,17 +147,17 @@ fn run(run_opts: RunOpts) -> i32 {
0
}
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
1
}
},
Task::InstallUpdate => match support::install_update() {
Ok(msg) => {
println!("{}", msg);
println!("{msg}");
0
}
Err(err) => {
eprintln!("Could not install update: {}", err);
eprintln!("Could not install update: {err}");
1
}
},
@@ -173,7 +172,7 @@ fn run(run_opts: RunOpts) -> i32 {
match ActivityManager::new(wrkdir.as_path(), run_opts.ticks) {
Ok(m) => m,
Err(err) => {
eprintln!("Could not start activity manager: {}", err);
eprintln!("Could not start activity manager: {err}");
return 1;
}
};
@@ -181,13 +180,13 @@ fn run(run_opts: RunOpts) -> i32 {
match run_opts.remote {
Remote::Bookmark(BookmarkParams { name, password }) => {
if let Err(err) = manager.resolve_bookmark_name(&name, password.as_deref()) {
eprintln!("{}", err);
eprintln!("{err}");
return 1;
}
}
Remote::Host(HostParams { params, password }) => {
if let Err(err) = manager.set_filetransfer_params(params, password.as_deref()) {
eprintln!("{}", err);
eprintln!("{err}");
return 1;
}
}

View File

@@ -23,7 +23,7 @@ pub fn import_theme(p: &Path) -> Result<(), String> {
));
}
// Validate theme file
ThemeProvider::new(p).map_err(|e| format!("Invalid theme error: {}", e))?;
ThemeProvider::new(p).map_err(|e| format!("Invalid theme error: {e}"))?;
// get config dir
let cfg_dir: PathBuf = get_config_dir()?;
// Get theme directory
@@ -31,7 +31,7 @@ pub fn import_theme(p: &Path) -> Result<(), String> {
// Copy theme to theme_dir
fs::copy(p, theme_file.as_path())
.map(|_| ())
.map_err(|e| format!("Could not import theme: {}", e))
.map_err(|e| format!("Could not import theme: {e}"))
}
/// ### install_update
@@ -51,7 +51,7 @@ pub fn install_update() -> Result<String, String> {
{
Notification::update_installed(v.as_str());
}
Ok(format!("termscp has been updated to version {}", v))
Ok(format!("termscp has been updated to version {v}"))
}
Err(err) => {
if get_config_client()
@@ -75,8 +75,7 @@ fn get_config_dir() -> Result<PathBuf, String> {
"Your system doesn't provide a configuration directory",
)),
Err(err) => Err(format!(
"Could not initialize configuration directory: {}",
err
"Could not initialize configuration directory: {err}"
)),
}
}

View File

@@ -88,7 +88,7 @@ impl BookmarksClient {
error!("Failed to set new key into storage: {}", e);
return Err(SerializerError::new_ex(
SerializerErrorKind::Io,
format!("Could not write key to storage: {}", e),
format!("Could not write key to storage: {e}"),
));
}
// Return key
@@ -98,7 +98,7 @@ impl BookmarksClient {
error!("Failed to get key from storage: {}", e);
return Err(SerializerError::new_ex(
SerializerErrorKind::Io,
format!("Could not get key from storage: {}", e),
format!("Could not get key from storage: {e}"),
));
}
},

View File

@@ -249,7 +249,7 @@ impl ConfigClient {
// Get key path
let ssh_key_path: PathBuf = {
let mut p: PathBuf = self.ssh_key_dir.clone();
p.push(format!("{}.key", host_name));
p.push(format!("{host_name}.key"));
p
};
info!(
@@ -390,7 +390,7 @@ impl ConfigClient {
/// Hosts are saved as `username@host` into configuration.
/// This method creates the key name, starting from host and username
fn make_ssh_host_key(host: &str, username: &str) -> String {
format!("{}@{}", username, host)
format!("{username}@{host}")
}
/// Get ssh tokens starting from ssh host key

View File

@@ -25,7 +25,7 @@ impl FileStorage {
/// Make file path for key file from `dir_path` and the application id
fn make_file_path(&self, storage_id: &str) -> PathBuf {
let mut p: PathBuf = self.dir_path.clone();
let file_name = format!(".{}.key", storage_id);
let file_name = format!(".{storage_id}.key");
p.push(file_name);
p
}

View File

@@ -33,7 +33,7 @@ pub fn init(level: LogLevel) -> Result<(), String> {
let config = ConfigBuilder::new().set_time_format_rfc3339().build();
// Make logger
WriteLogger::init(level, config, file)
.map_err(|e| format!("Failed to initialize logger: {}", e))
.map_err(|e| format!("Failed to initialize logger: {e}"))
}
#[cfg(test)]

View File

@@ -29,7 +29,7 @@ impl SshKeyStorage {
/// Make mapkey from host and username
fn make_mapkey(host: &str, username: &str) -> String {
format!("{}@{}", username, host)
format!("{username}@{host}")
}
#[cfg(test)]
@@ -46,11 +46,11 @@ impl SshKeyStorage {
use std::io::BufReader;
let mut reader = File::open(path)
.map_err(|e| format!("failed to open {}: {}", path, e))
.map_err(|e| format!("failed to open {path}: {e}"))
.map(BufReader::new)?;
SshConfig::default()
.parse(&mut reader)
.map_err(|e| format!("Failed to parse ssh2 config: {}", e))
.map_err(|e| format!("Failed to parse ssh2 config: {e}"))
}
/// Resolve host via termscp ssh keys storage

View File

@@ -102,7 +102,7 @@ impl AuthActivity {
fn write_bookmarks(&mut self) {
if let Some(bookmarks_cli) = self.bookmarks_client() {
if let Err(err) = bookmarks_cli.write_bookmarks() {
self.mount_error(format!("Could not write bookmarks: {}", err).as_str());
self.mount_error(format!("Could not write bookmarks: {err}").as_str());
}
}
}

View File

@@ -107,7 +107,7 @@ impl AuthActivity {
// Report error
error!("Failed to get latest version: {}", err);
self.mount_error(
format!("Could not check for new updates: {}", err).as_str(),
format!("Could not check for new updates: {err}").as_str(),
);
}
}
@@ -136,13 +136,13 @@ impl AuthActivity {
if self.config().get_notifications() {
Notification::update_installed(ver.as_str());
}
self.mount_info(format!("termscp has been updated to version {}!", ver))
self.mount_info(format!("termscp has been updated to version {ver}!"))
}
Err(err) => {
if self.config().get_notifications() {
Notification::update_failed(err.to_string());
}
self.mount_error(format!("Could not install update: {}", err))
self.mount_error(format!("Could not install update: {err}"))
}
}
}

View File

@@ -275,7 +275,7 @@ impl Activity for AuthActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
// View

View File

@@ -881,7 +881,7 @@ impl AuthActivity {
/// Format bookmark to display on ui
fn fmt_bookmark(name: &str, b: FileTransferParams) -> String {
let addr: String = Self::fmt_recent(b);
format!("{} ({})", name, addr)
format!("{name} ({addr})")
}
/// Format recent connection to display on ui
@@ -890,7 +890,7 @@ impl AuthActivity {
match b.params {
ProtocolParams::AwsS3(s3) => {
let profile: String = match s3.profile {
Some(p) => format!("[{}]", p),
Some(p) => format!("[{p}]"),
None => String::default(),
};
format!(
@@ -905,7 +905,7 @@ impl AuthActivity {
ProtocolParams::Generic(params) => {
let username: String = match params.username {
None => String::default(),
Some(u) => format!("{}@", u),
Some(u) => format!("{u}@"),
};
format!(
"{}://{}{}:{}",

View File

@@ -159,8 +159,7 @@ impl FileTransferActivity {
self.log(
LogLevel::Warn,
format!(
"Refused to create '{}'; synchronized browsing disabled",
name
"Refused to create '{name}'; synchronized browsing disabled"
),
);
self.browser.toggle_sync_browsing();

View File

@@ -116,7 +116,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not create temporary directory: {}", err),
format!("Copy failed: could not create temporary directory: {err}"),
);
return Err(err.to_string());
}
@@ -130,7 +130,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: failed to download file: {}", err),
format!("Copy failed: failed to download file: {err}"),
);
return Err(err);
}
@@ -158,7 +158,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: failed to send file: {}", err),
format!("Copy failed: failed to send file: {err}"),
);
return Err(err);
}
@@ -170,7 +170,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not create temporary file: {}", err),
format!("Copy failed: could not create temporary file: {err}"),
);
return Err(String::from("Could not create temporary file"));
}
@@ -183,7 +183,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Copy failed: could not download to temporary file: {}", err),
format!("Copy failed: could not download to temporary file: {err}"),
);
return Err(err);
}

View File

@@ -71,12 +71,12 @@ impl FileTransferActivity {
}
}
Err(err) => {
return Err(format!("Could not read file: {}", err));
return Err(format!("Could not read file: {err}"));
}
}
}
Err(err) => {
return Err(format!("Could not read file: {}", err));
return Err(format!("Could not read file: {err}"));
}
}
// Put input mode back to normal
@@ -98,7 +98,7 @@ impl FileTransferActivity {
path.display()
),
),
Err(err) => return Err(format!("Could not open editor: {}", err)),
Err(err) => return Err(format!("Could not open editor: {err}")),
}
if let Some(ctx) = self.context.as_mut() {
// Enter alternate mode
@@ -134,7 +134,7 @@ impl FileTransferActivity {
tmpfile.as_path(),
Some(file_name.clone()),
) {
return Err(format!("Could not open file {}: {}", file_name, err));
return Err(format!("Could not open file {file_name}: {err}"));
}
// Get current file modification time
let prev_mtime: SystemTime = match self.host.stat(tmpfile.as_path()) {

View File

@@ -10,13 +10,13 @@ impl FileTransferActivity {
match self.host.exec(input.as_str()) {
Ok(output) => {
// Reload files
self.log(LogLevel::Info, format!("\"{}\": {}", input, output));
self.log(LogLevel::Info, format!("\"{input}\": {output}"));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not execute command \"{}\": {}", input, err),
format!("Could not execute command \"{input}\": {err}"),
);
}
}
@@ -28,14 +28,14 @@ impl FileTransferActivity {
// Reload files
self.log(
LogLevel::Info,
format!("\"{}\" (exitcode: {}): {}", input, rc, output),
format!("\"{input}\" (exitcode: {rc}): {output}"),
);
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not execute command \"{}\": {}", input, err),
format!("Could not execute command \"{input}\": {err}"),
);
}
}

View File

@@ -12,14 +12,14 @@ impl FileTransferActivity {
pub(crate) fn action_local_find(&mut self, input: String) -> Result<Vec<File>, String> {
match self.host.find(input.as_str()) {
Ok(entries) => Ok(entries),
Err(err) => Err(format!("Could not search for files: {}", err)),
Err(err) => Err(format!("Could not search for files: {err}")),
}
}
pub(crate) fn action_remote_find(&mut self, input: String) -> Result<Vec<File>, String> {
match self.client.as_mut().find(input.as_str()) {
Ok(entries) => Ok(entries),
Err(err) => Err(format!("Could not search for files: {}", err)),
Err(err) => Err(format!("Could not search for files: {err}")),
}
}
@@ -72,7 +72,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -94,7 +94,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}
@@ -133,7 +133,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -163,7 +163,7 @@ impl FileTransferActivity {
) {
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}

View File

@@ -12,13 +12,13 @@ impl FileTransferActivity {
match self.host.mkdir(PathBuf::from(input.as_str()).as_path()) {
Ok(_) => {
// Reload files
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
self.log(LogLevel::Info, format!("Created directory \"{input}\""));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not create directory \"{}\": {}", input, err),
format!("Could not create directory \"{input}\": {err}"),
);
}
}
@@ -30,13 +30,13 @@ impl FileTransferActivity {
) {
Ok(_) => {
// Reload files
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
self.log(LogLevel::Info, format!("Created directory \"{input}\""));
}
Err(err) => {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not create directory \"{}\": {}", input, err),
format!("Could not create directory \"{input}\": {err}"),
);
}
}

View File

@@ -19,7 +19,7 @@ impl FileTransferActivity {
if file_exists {
self.log_and_alert(
LogLevel::Warn,
format!("File \"{}\" already exists", input,),
format!("File \"{input}\" already exists",),
);
return;
}
@@ -49,7 +49,7 @@ impl FileTransferActivity {
if file_exists {
self.log_and_alert(
LogLevel::Warn,
format!("File \"{}\" already exists", input,),
format!("File \"{input}\" already exists",),
);
return;
}
@@ -59,7 +59,7 @@ impl FileTransferActivity {
match tempfile::NamedTempFile::new() {
Err(err) => self.log_and_alert(
LogLevel::Error,
format!("Could not create tempfile: {}", err),
format!("Could not create tempfile: {err}"),
),
Ok(tfile) => {
// Stat tempfile
@@ -67,7 +67,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not stat tempfile: {}", err),
format!("Could not stat tempfile: {err}"),
);
return;
}
@@ -80,7 +80,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not open tempfile: {}", err),
format!("Could not open tempfile: {err}"),
);
return;
}

View File

@@ -71,7 +71,7 @@ impl FileTransferActivity {
Err(err) => {
self.log(
LogLevel::Error,
format!("Failed to download remote entry: {}", err),
format!("Failed to download remote entry: {err}"),
);
}
}

View File

@@ -47,7 +47,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -82,7 +82,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not upload file: {}", err),
format!("Could not upload file: {err}"),
);
}
}
@@ -111,7 +111,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}
@@ -146,7 +146,7 @@ impl FileTransferActivity {
{
self.log_and_alert(
LogLevel::Error,
format!("Could not download file: {}", err),
format!("Could not download file: {err}"),
);
}
}

View File

@@ -29,7 +29,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not create symlink: {}", err),
format!("Could not create symlink: {err}"),
);
}
}

View File

@@ -111,7 +111,7 @@ impl FileTransferActivity {
);
}
Some(Err(err)) => {
self.log_and_alert(LogLevel::Error, format!("could not unwatch path: {}", err));
self.log_and_alert(LogLevel::Error, format!("could not unwatch path: {err}"));
}
None => {}
}

View File

@@ -415,7 +415,7 @@ impl FileInfoPopup {
texts
.add_row()
.add_col(TextSpan::from("Size: "))
.add_col(TextSpan::new(format!("{} ({})", bsize, size).as_str()).fg(Color::Cyan));
.add_col(TextSpan::new(format!("{bsize} ({size})").as_str()).fg(Color::Cyan));
let atime: String = fmt_time(
file.metadata().accessed.unwrap_or(UNIX_EPOCH),
"%b %d %Y %H:%M:%S",
@@ -1330,7 +1330,7 @@ pub struct ReplacePopup {
impl ReplacePopup {
pub fn new(filename: Option<&str>, color: Color) -> Self {
let text = match filename {
Some(f) => format!(r#"File "{}" already exists. Overwrite file?"#, f),
Some(f) => format!(r#"File "{f}" already exists. Overwrite file?"#),
None => "Overwrite files?".to_string(),
};
Self {
@@ -1795,8 +1795,7 @@ impl SyncBrowsingMkdirPopup {
.choices(&["Yes", "No"])
.title(
format!(
r#"Sync browsing: directory "{}" doesn't exist. Do you want to create it?"#,
dir_name
r#"Sync browsing: directory "{dir_name}" doesn't exist. Do you want to create it?"#
),
Alignment::Center,
),
@@ -1974,8 +1973,8 @@ pub struct WatcherPopup {
impl WatcherPopup {
pub fn new(watched: bool, local: &str, remote: &str, color: Color) -> Self {
let text = match watched {
false => format!(r#"Synchronize changes from "{}" to "{}"?"#, local, remote),
true => format!(r#"Stop synchronizing changes at "{}"?"#, local),
false => format!(r#"Synchronize changes from "{local}" to "{remote}"?"#),
true => format!(r#"Stop synchronizing changes at "{local}"?"#),
};
Self {
component: Radio::default()

View File

@@ -38,7 +38,7 @@ impl FileTransferActivity {
Err(err) => {
self.log(
LogLevel::Error,
format!("error while polling file watcher: {}", err),
format!("error while polling file watcher: {err}"),
);
}
}

View File

@@ -35,7 +35,7 @@ impl FileTransferActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
}

View File

@@ -287,7 +287,7 @@ impl FileTransferActivity {
);
match file_type {
None => base,
Some(file_type) => format!("{}.{}", base, file_type),
Some(file_type) => format!("{base}.{file_type}"),
}
})
}

View File

@@ -134,7 +134,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
format!("Could not scan current directory: {err}"),
);
}
}
@@ -150,7 +150,7 @@ impl FileTransferActivity {
Err(err) => {
self.log_and_alert(
LogLevel::Error,
format!("Could not scan current directory: {}", err),
format!("Could not scan current directory: {err}"),
);
}
}
@@ -435,7 +435,7 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(file_size);
// rewind
if let Err(err) = reader.seek(std::io::SeekFrom::Start(0)) {
if let Err(err) = reader.rewind() {
return Err(TransferErrorReason::CouldNotRewind(err));
}
// Write remote file
@@ -491,7 +491,7 @@ impl FileTransferActivity {
// Draw only if a significant progress has been made (performance improvement)
if last_progress_val < self.transfer.partial.calc_progress() - 0.01 {
// Draw
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
last_progress_val = self.transfer.partial.calc_progress();
}
@@ -500,7 +500,7 @@ impl FileTransferActivity {
if let Err(err) = self.client.on_written(writer) {
self.log(
LogLevel::Warn,
format!("Could not finalize remote stream: \"{}\"", err),
format!("Could not finalize remote stream: \"{err}\""),
);
}
// if upload was abrupted, return error
@@ -539,11 +539,11 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(file_size);
// rewind
if let Err(err) = reader.seek(std::io::SeekFrom::Start(0)) {
if let Err(err) = reader.rewind() {
return Err(TransferErrorReason::CouldNotRewind(err));
}
// Draw before
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
// Send file
if let Err(err) = self.client.create_file(remote, &metadata, Box::new(reader)) {
@@ -553,7 +553,7 @@ impl FileTransferActivity {
self.transfer.partial.update_progress(file_size);
self.transfer.full.update_progress(file_size);
// Draw again after
self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.update_progress_bar(format!("Uploading \"{file_name}\""));
self.view();
// log and return Ok
self.log(
@@ -892,7 +892,7 @@ impl FileTransferActivity {
// Draw only if a significant progress has been made (performance improvement)
if last_progress_val < self.transfer.partial.calc_progress() - 0.01 {
// Draw
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
last_progress_val = self.transfer.partial.calc_progress();
}
@@ -901,7 +901,7 @@ impl FileTransferActivity {
if let Err(err) = self.client.on_read(reader) {
self.log(
LogLevel::Warn,
format!("Could not finalize remote stream: \"{}\"", err),
format!("Could not finalize remote stream: \"{err}\""),
);
}
// If download was abrupted, return Error
@@ -953,7 +953,7 @@ impl FileTransferActivity {
// Init transfer
self.transfer.partial.init(remote.metadata.size as usize);
// Draw before transfer
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
// recv wno stream
if let Err(err) = self.client.open_file(remote.path.as_path(), reader) {
@@ -967,7 +967,7 @@ impl FileTransferActivity {
.full
.update_progress(remote.metadata.size as usize);
// Draw after transfer
self.update_progress_bar(format!("Downloading \"{}\"", file_name));
self.update_progress_bar(format!("Downloading \"{file_name}\""));
self.view();
// Apply file mode to file
#[cfg(target_family = "unix")]
@@ -1018,7 +1018,7 @@ impl FileTransferActivity {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not change working directory: {}", err),
format!("Could not change working directory: {err}"),
);
}
}
@@ -1045,7 +1045,7 @@ impl FileTransferActivity {
// Report err
self.log_and_alert(
LogLevel::Error,
format!("Could not change working directory: {}", err),
format!("Could not change working directory: {err}"),
);
}
}

View File

@@ -131,7 +131,7 @@ impl FileTransferActivity {
TransferMsg::ExecuteCmd(cmd) => {
// Exex command
self.umount_exec();
self.mount_blocking_wait(format!("Executing '{}'…", cmd).as_str());
self.mount_blocking_wait(format!("Executing '{cmd}'…").as_str());
match self.browser.tab() {
FileExplorerTab::Local => self.action_local_exec(cmd),
FileExplorerTab::Remote => self.action_remote_exec(cmd),
@@ -271,7 +271,7 @@ impl FileTransferActivity {
TransferMsg::SearchFile(search) => {
self.umount_find_input();
// Mount wait
self.mount_blocking_wait(format!(r#"Searching for "{}"…"#, search).as_str());
self.mount_blocking_wait(format!(r#"Searching for "{search}"…"#).as_str());
// Find
let res: Result<Vec<File>, String> = match self.browser.tab() {
FileExplorerTab::Local => self.action_local_find(search.clone()),
@@ -289,7 +289,7 @@ impl FileTransferActivity {
Ok(files) if files.is_empty() => {
// If no file has been found notify user
self.mount_info(
format!(r#"Could not find any file matching "{}""#, search).as_str(),
format!(r#"Could not find any file matching "{search}""#).as_str(),
);
}
Ok(files) => {

View File

@@ -490,7 +490,7 @@ impl FileTransferActivity {
.remount(
Id::ExplorerFind,
Box::new(components::ExplorerFind::new(
format!(r#"Search results for "{}""#, search),
format!(r#"Search results for "{search}""#),
&[],
bg,
fg,

View File

@@ -46,7 +46,7 @@ impl SetupActivity {
// Collect input values if in theme form
if self.layout == ViewLayout::Theme {
self.collect_styles()
.map_err(|e| format!("'{:?}' has an invalid color", e))?;
.map_err(|e| format!("'{e:?}' has an invalid color"))?;
}
// save theme
self.save_theme()
@@ -59,7 +59,7 @@ impl SetupActivity {
ViewLayout::SetupForm => self.collect_input_values(),
ViewLayout::Theme => self
.collect_styles()
.map_err(|e| format!("'{:?}' has an invalid color", e))?,
.map_err(|e| format!("'{e:?}' has an invalid color"))?,
_ => {}
}
// Update view
@@ -113,7 +113,7 @@ impl SetupActivity {
Err(err) => {
// Report error
self.mount_error(
format!("Could not get ssh key \"{}\": {}", key, err).as_str(),
format!("Could not get ssh key \"{key}\": {err}").as_str(),
);
}
}
@@ -134,7 +134,7 @@ impl SetupActivity {
};
// Prepare text editor
env::set_var("EDITOR", self.config().get_text_editor());
let placeholder: String = format!("# Type private SSH key for {}@{}\n", username, host);
let placeholder: String = format!("# Type private SSH key for {username}@{host}\n");
// Put input mode back to normal
if let Err(err) = self.context_mut().terminal().disable_raw_mode() {
error!("Could not disable raw mode: {}", err);
@@ -159,14 +159,14 @@ impl SetupActivity {
self.add_ssh_key(host.as_str(), username.as_str(), rsa_key.as_str())
{
self.mount_error(
format!("Could not create new private key: {}", err).as_str(),
format!("Could not create new private key: {err}").as_str(),
);
}
}
}
Err(err) => {
// Report error
self.mount_error(format!("Could not write private key to file: {}", err).as_str());
self.mount_error(format!("Could not write private key to file: {err}").as_str());
}
}
// Restore terminal

View File

@@ -15,7 +15,7 @@ impl SetupActivity {
Ok(_) => Ok(()),
Err(err) => {
error!("Could not save configuration: {}", err);
Err(format!("Could not save configuration: {}", err))
Err(format!("Could not save configuration: {err}"))
}
}
}
@@ -25,21 +25,21 @@ impl SetupActivity {
pub(super) fn reset_config_changes(&mut self) -> Result<(), String> {
self.config_mut()
.read_config()
.map_err(|e| format!("Could not reload configuration: {}", e))
.map_err(|e| format!("Could not reload configuration: {e}"))
}
/// Save theme to file
pub(super) fn save_theme(&mut self) -> Result<(), String> {
self.theme_provider()
.save()
.map_err(|e| format!("Could not save theme: {}", e))
.map_err(|e| format!("Could not save theme: {e}"))
}
/// Reset changes committed to theme
pub(super) fn reset_theme_changes(&mut self) -> Result<(), String> {
self.theme_provider()
.load()
.map_err(|e| format!("Could not restore theme: {}", e))
.map_err(|e| format!("Could not restore theme: {e}"))
}
/// Delete ssh key from config cli
@@ -47,8 +47,7 @@ impl SetupActivity {
match self.config_mut().del_ssh_key(host, username) {
Ok(_) => Ok(()),
Err(err) => Err(format!(
"Could not delete ssh key \"{}@{}\": {}",
host, username, err
"Could not delete ssh key \"{host}@{username}\": {err}"
)),
}
}
@@ -80,11 +79,11 @@ impl SetupActivity {
Some((_, _, key_path)) => {
match edit::edit_file(key_path.as_path()) {
Ok(_) => Ok(()),
Err(err) => Err(format!("Could not edit ssh key: {}", err)),
Err(err) => Err(format!("Could not edit ssh key: {err}")),
}
}
},
Err(err) => Err(format!("Could not read ssh key: {}", err)),
Err(err) => Err(format!("Could not read ssh key: {err}")),
}
}
None => Ok(()),
@@ -119,6 +118,6 @@ impl SetupActivity {
) -> Result<(), String> {
self.config_mut()
.add_ssh_key(host, username, rsa_key)
.map_err(|e| format!("Could not add SSH key: {}", e))
.map_err(|e| format!("Could not add SSH key: {e}"))
}
}

View File

@@ -352,7 +352,7 @@ impl Activity for SetupActivity {
}
}
Err(err) => {
self.mount_error(format!("Application error: {}", err));
self.mount_error(format!("Application error: {err}"));
}
}
// View

View File

@@ -124,7 +124,7 @@ impl SetupActivity {
.iter_ssh_keys()
.map(|x| {
let (addr, username, _) = self.config().get_ssh_key(x).ok().unwrap().unwrap();
format!("{} at {}", username, addr)
format!("{username} at {addr}")
})
.collect();
assert!(self

View File

@@ -254,7 +254,7 @@ pub fn fmt_color(color: &Color) -> String {
Color::Rgb(255, 255, 0) => "yellow".to_string(),
Color::Rgb(154, 205, 50) => "yellowgreen".to_string(),
// -- others
Color::Rgb(r, g, b) => format!("#{:02x}{:02x}{:02x}", r, g, b),
Color::Rgb(r, g, b) => format!("#{r:02x}{g:02x}{b:02x}"),
}
}
@@ -280,7 +280,7 @@ pub fn fmt_bytes(v: u64) -> String {
} else if v >= 1024 {
format!("{} KB", v / 1024)
} else {
format!("{} B", v)
format!("{v} B")
}
}

View File

@@ -29,7 +29,7 @@ pub fn create_sample_file() -> NamedTempFile {
/// Create sample file with provided content
pub fn create_sample_file_with_content(content: impl std::fmt::Display) -> NamedTempFile {
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
writeln!(tmpfile, "{}", content).unwrap();
writeln!(tmpfile, "{content}").unwrap();
tmpfile
}