mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Changed log function to accept String instead of &str
This commit is contained in:
@@ -199,8 +199,7 @@ impl FileTransferActivity {
|
||||
"Copied \"{}\" to \"{}\"",
|
||||
entry.get_abs_path().display(),
|
||||
dest_path.display()
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
);
|
||||
// Reload entries
|
||||
let wrkdir: PathBuf = self.local.wrkdir.clone();
|
||||
@@ -234,8 +233,7 @@ impl FileTransferActivity {
|
||||
"Copied \"{}\" to \"{}\"",
|
||||
entry.get_abs_path().display(),
|
||||
dest_path.display()
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
);
|
||||
self.reload_remote_dir();
|
||||
}
|
||||
@@ -256,10 +254,7 @@ impl FileTransferActivity {
|
||||
match self.host.mkdir(PathBuf::from(input.as_str()).as_path()) {
|
||||
Ok(_) => {
|
||||
// Reload files
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created directory \"{}\"", input).as_ref(),
|
||||
);
|
||||
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
||||
let wrkdir: PathBuf = self.local.wrkdir.clone();
|
||||
self.local_scan(wrkdir.as_path());
|
||||
}
|
||||
@@ -280,10 +275,7 @@ impl FileTransferActivity {
|
||||
{
|
||||
Ok(_) => {
|
||||
// Reload files
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created directory \"{}\"", input).as_ref(),
|
||||
);
|
||||
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
||||
self.reload_remote_dir();
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -320,8 +312,7 @@ impl FileTransferActivity {
|
||||
"Renamed file \"{}\" to \"{}\"",
|
||||
full_path.display(),
|
||||
dst_path.display()
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -352,8 +343,7 @@ impl FileTransferActivity {
|
||||
"Renamed file \"{}\" to \"{}\"",
|
||||
full_path.display(),
|
||||
dst_path.display()
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -380,7 +370,7 @@ impl FileTransferActivity {
|
||||
// Log
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Removed file \"{}\"", full_path.display()).as_ref(),
|
||||
format!("Removed file \"{}\"", full_path.display()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -404,7 +394,7 @@ impl FileTransferActivity {
|
||||
self.reload_remote_dir();
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Removed file \"{}\"", full_path.display()).as_ref(),
|
||||
format!("Removed file \"{}\"", full_path.display()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -467,7 +457,7 @@ impl FileTransferActivity {
|
||||
} else {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created file \"{}\"", file_path.display()).as_str(),
|
||||
format!("Created file \"{}\"", file_path.display()),
|
||||
);
|
||||
}
|
||||
// Reload files
|
||||
@@ -527,7 +517,7 @@ impl FileTransferActivity {
|
||||
} else {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created file \"{}\"", file_path.display()).as_str(),
|
||||
format!("Created file \"{}\"", file_path.display()),
|
||||
);
|
||||
}
|
||||
// Reload files
|
||||
@@ -544,10 +534,7 @@ impl FileTransferActivity {
|
||||
match self.host.exec(input.as_str()) {
|
||||
Ok(output) => {
|
||||
// Reload files
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("\"{}\": {}", input, output).as_ref(),
|
||||
);
|
||||
self.log(LogLevel::Info, format!("\"{}\": {}", input, output));
|
||||
let wrkdir: PathBuf = self.local.wrkdir.clone();
|
||||
self.local_scan(wrkdir.as_path());
|
||||
}
|
||||
@@ -565,10 +552,7 @@ impl FileTransferActivity {
|
||||
match self.client.as_mut().exec(input.as_str()) {
|
||||
Ok(output) => {
|
||||
// Reload files
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("\"{}\": {}", input, output).as_ref(),
|
||||
);
|
||||
self.log(LogLevel::Info, format!("\"{}\": {}", input, output));
|
||||
self.reload_remote_dir();
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -651,7 +635,7 @@ impl FileTransferActivity {
|
||||
// Log
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Removed file \"{}\"", full_path.display()).as_ref(),
|
||||
format!("Removed file \"{}\"", full_path.display()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -674,7 +658,7 @@ impl FileTransferActivity {
|
||||
self.reload_remote_dir();
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Removed file \"{}\"", full_path.display()).as_ref(),
|
||||
format!("Removed file \"{}\"", full_path.display()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -693,6 +677,50 @@ impl FileTransferActivity {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn action_edit_local_file(&mut self) {
|
||||
if self.get_local_file_entry().is_some() {
|
||||
let fsentry: FsEntry = self.get_local_file_entry().unwrap().clone();
|
||||
// Check if file
|
||||
if fsentry.is_file() {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Opening file \"{}\"...", fsentry.get_abs_path().display()),
|
||||
);
|
||||
// Edit file
|
||||
match self.edit_local_file(fsentry.get_abs_path().as_path()) {
|
||||
Ok(_) => {
|
||||
// Reload directory
|
||||
let pwd: PathBuf = self.local.wrkdir.clone();
|
||||
self.local_scan(pwd.as_path());
|
||||
}
|
||||
Err(err) => self.log_and_alert(LogLevel::Error, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn action_edit_remote_file(&mut self) {
|
||||
if self.get_remote_file_entry().is_some() {
|
||||
let fsentry: FsEntry = self.get_remote_file_entry().unwrap().clone();
|
||||
// Check if file
|
||||
if let FsEntry::File(file) = fsentry.clone() {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Opening file \"{}\"...", fsentry.get_abs_path().display()),
|
||||
);
|
||||
// Edit file
|
||||
match self.edit_remote_file(&file) {
|
||||
Ok(_) => {
|
||||
// Reload directory
|
||||
let pwd: PathBuf = self.remote.wrkdir.clone();
|
||||
self.remote_scan(pwd.as_path());
|
||||
}
|
||||
Err(err) => self.log_and_alert(LogLevel::Error, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_local_file_entry
|
||||
///
|
||||
/// Get local file entry
|
||||
|
||||
@@ -34,7 +34,7 @@ impl FileTransferActivity {
|
||||
/// ### log
|
||||
///
|
||||
/// Add message to log events
|
||||
pub(super) fn log(&mut self, level: LogLevel, msg: &str) {
|
||||
pub(super) fn log(&mut self, level: LogLevel, msg: String) {
|
||||
// Create log record
|
||||
let record: LogRecord = LogRecord::new(level, msg);
|
||||
//Check if history overflows the size
|
||||
@@ -52,8 +52,8 @@ impl FileTransferActivity {
|
||||
///
|
||||
/// Add message to log events and also display it as an alert
|
||||
pub(super) fn log_and_alert(&mut self, level: LogLevel, msg: String) {
|
||||
self.log(level, msg.as_str());
|
||||
self.mount_error(msg.as_str());
|
||||
self.log(level, msg);
|
||||
// Update log
|
||||
let msg = self.update_logbox();
|
||||
self.update(msg);
|
||||
|
||||
@@ -119,11 +119,11 @@ impl LogRecord {
|
||||
/// ### new
|
||||
///
|
||||
/// Instantiates a new LogRecord
|
||||
pub fn new(level: LogLevel, msg: &str) -> LogRecord {
|
||||
pub fn new(level: LogLevel, msg: String) -> LogRecord {
|
||||
LogRecord {
|
||||
time: Local::now(),
|
||||
level,
|
||||
msg: String::from(msg),
|
||||
msg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl FileTransferActivity {
|
||||
// Log welcome
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Established connection with '{}': \"{}\"", addr, banner).as_ref(),
|
||||
format!("Established connection with '{}': \"{}\"", addr, banner),
|
||||
);
|
||||
}
|
||||
// Try to change directory to entry directory
|
||||
@@ -192,8 +192,7 @@ impl FileTransferActivity {
|
||||
"Could not remove created file {}: {}",
|
||||
remote_path.display(),
|
||||
err
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
),
|
||||
Ok(entry) => {
|
||||
if let Err(err) = self.client.remove(&entry) {
|
||||
@@ -203,8 +202,7 @@ impl FileTransferActivity {
|
||||
"Could not remove created file {}: {}",
|
||||
remote_path.display(),
|
||||
err
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +216,7 @@ impl FileTransferActivity {
|
||||
Ok(_) => {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created directory \"{}\"", remote_path.display()).as_ref(),
|
||||
format!("Created directory \"{}\"", remote_path.display()),
|
||||
);
|
||||
// Get files in dir
|
||||
match self.host.scan_dir(dir.abs_path.as_path()) {
|
||||
@@ -324,8 +322,7 @@ impl FileTransferActivity {
|
||||
"Could not remove created file {}: {}",
|
||||
local_file_path.display(),
|
||||
err
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
),
|
||||
Ok(entry) => {
|
||||
if let Err(err) = self.host.remove(&entry) {
|
||||
@@ -335,8 +332,7 @@ impl FileTransferActivity {
|
||||
"Could not remove created file {}: {}",
|
||||
local_file_path.display(),
|
||||
err
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -365,14 +361,13 @@ impl FileTransferActivity {
|
||||
pex,
|
||||
local_dir_path.display(),
|
||||
err
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Created directory \"{}\"", local_dir_path.display()).as_ref(),
|
||||
format!("Created directory \"{}\"", local_dir_path.display()),
|
||||
);
|
||||
// Get files in dir
|
||||
match self.client.list_dir(dir.abs_path.as_path()) {
|
||||
@@ -407,8 +402,7 @@ impl FileTransferActivity {
|
||||
"Failed to create directory \"{}\": {}",
|
||||
local_dir_path.display(),
|
||||
err
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -519,7 +513,7 @@ impl FileTransferActivity {
|
||||
if let Err(err) = self.client.on_sent(rhnd) {
|
||||
self.log(
|
||||
LogLevel::Warn,
|
||||
format!("Could not finalize remote stream: \"{}\"", err).as_str(),
|
||||
format!("Could not finalize remote stream: \"{}\"", err),
|
||||
);
|
||||
}
|
||||
// if upload was abrupted, return error
|
||||
@@ -534,8 +528,7 @@ impl FileTransferActivity {
|
||||
remote.display(),
|
||||
fmt_millis(self.transfer.started.elapsed()),
|
||||
ByteSize(self.transfer.bytes_per_second()),
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => return Err(TransferErrorReason::FileTransferError(err)),
|
||||
@@ -622,7 +615,7 @@ impl FileTransferActivity {
|
||||
if let Err(err) = self.client.on_recv(rhnd) {
|
||||
self.log(
|
||||
LogLevel::Warn,
|
||||
format!("Could not finalize remote stream: \"{}\"", err).as_str(),
|
||||
format!("Could not finalize remote stream: \"{}\"", err),
|
||||
);
|
||||
}
|
||||
// If download was abrupted, return Error
|
||||
@@ -640,8 +633,7 @@ impl FileTransferActivity {
|
||||
pex,
|
||||
local.display(),
|
||||
err
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -654,8 +646,7 @@ impl FileTransferActivity {
|
||||
local.display(),
|
||||
fmt_millis(self.transfer.started.elapsed()),
|
||||
ByteSize(self.transfer.bytes_per_second()),
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => return Err(TransferErrorReason::FileTransferError(err)),
|
||||
@@ -713,7 +704,7 @@ impl FileTransferActivity {
|
||||
Ok(_) => {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Changed directory on local: {}", path.display()).as_str(),
|
||||
format!("Changed directory on local: {}", path.display()),
|
||||
);
|
||||
// Reload files
|
||||
self.local_scan(path);
|
||||
@@ -742,7 +733,7 @@ impl FileTransferActivity {
|
||||
Ok(_) => {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Changed directory on remote: {}", path.display()).as_str(),
|
||||
format!("Changed directory on remote: {}", path.display()),
|
||||
);
|
||||
// Update files
|
||||
self.remote_scan(path);
|
||||
@@ -800,8 +791,7 @@ impl FileTransferActivity {
|
||||
format!(
|
||||
"Changes performed through editor saved to \"{}\"!",
|
||||
path.display()
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
),
|
||||
Err(err) => return Err(format!("Could not open editor: {}", err)),
|
||||
}
|
||||
@@ -865,8 +855,7 @@ impl FileTransferActivity {
|
||||
format!(
|
||||
"File \"{}\" has changed; writing changes to remote",
|
||||
file.abs_path.display()
|
||||
)
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
// Get local fs entry
|
||||
let tmpfile_entry: FsEntry = match self.host.stat(tmpfile.path()) {
|
||||
@@ -900,7 +889,7 @@ impl FileTransferActivity {
|
||||
false => {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("File \"{}\" hasn't changed", file.abs_path.display()).as_ref(),
|
||||
format!("File \"{}\" hasn't changed", file.abs_path.display()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,27 +135,7 @@ impl FileTransferActivity {
|
||||
self.update_local_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_O) => {
|
||||
// Clone entry due to mutable stuff...
|
||||
if self.get_local_file_entry().is_some() {
|
||||
let fsentry: FsEntry = self.get_local_file_entry().unwrap().clone();
|
||||
// Check if file
|
||||
if fsentry.is_file() {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Opening file \"{}\"...", fsentry.get_abs_path().display())
|
||||
.as_str(),
|
||||
);
|
||||
// Edit file
|
||||
match self.edit_local_file(fsentry.get_abs_path().as_path()) {
|
||||
Ok(_) => {
|
||||
// Reload directory
|
||||
let pwd: PathBuf = self.local.wrkdir.clone();
|
||||
self.local_scan(pwd.as_path());
|
||||
}
|
||||
Err(err) => self.log_and_alert(LogLevel::Error, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
self.action_edit_local_file();
|
||||
// Reload file list component
|
||||
self.update_local_filelist()
|
||||
}
|
||||
@@ -238,27 +218,8 @@ impl FileTransferActivity {
|
||||
self.update_remote_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_O) => {
|
||||
// Clone entry due to mutable stuff...
|
||||
if self.get_remote_file_entry().is_some() {
|
||||
let fsentry: FsEntry = self.get_remote_file_entry().unwrap().clone();
|
||||
// Check if file
|
||||
if let FsEntry::File(file) = fsentry.clone() {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
format!("Opening file \"{}\"...", fsentry.get_abs_path().display())
|
||||
.as_str(),
|
||||
);
|
||||
// Edit file
|
||||
match self.edit_remote_file(&file) {
|
||||
Ok(_) => {
|
||||
// Reload directory
|
||||
let pwd: PathBuf = self.remote.wrkdir.clone();
|
||||
self.remote_scan(pwd.as_path());
|
||||
}
|
||||
Err(err) => self.log_and_alert(LogLevel::Error, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
// Edit file
|
||||
self.action_edit_remote_file();
|
||||
// Reload file list component
|
||||
self.update_remote_filelist()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user