mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Localhost in activity; no more in Context
This commit is contained in:
@@ -221,13 +221,7 @@ impl FileTransferActivity {
|
||||
format!("Created directory \"{}\"", remote_path.display()).as_ref(),
|
||||
);
|
||||
// Get files in dir
|
||||
match self
|
||||
.context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.local
|
||||
.scan_dir(dir.abs_path.as_path())
|
||||
{
|
||||
match self.host.scan_dir(dir.abs_path.as_path()) {
|
||||
Ok(entries) => {
|
||||
// Iterate over files
|
||||
for entry in entries.iter() {
|
||||
@@ -322,9 +316,8 @@ impl FileTransferActivity {
|
||||
err,
|
||||
TransferErrorReason::Abrupted | TransferErrorReason::LocalIoError(_)
|
||||
) {
|
||||
let local = &mut self.context.as_mut().unwrap().local;
|
||||
// Stat file
|
||||
match local.stat(local_file_path.as_path()) {
|
||||
match self.host.stat(local_file_path.as_path()) {
|
||||
Err(err) => self.log(
|
||||
LogLevel::Error,
|
||||
format!(
|
||||
@@ -335,7 +328,7 @@ impl FileTransferActivity {
|
||||
.as_str(),
|
||||
),
|
||||
Ok(entry) => {
|
||||
if let Err(err) = local.remove(&entry) {
|
||||
if let Err(err) = self.host.remove(&entry) {
|
||||
self.log(
|
||||
LogLevel::Error,
|
||||
format!(
|
||||
@@ -359,24 +352,12 @@ impl FileTransferActivity {
|
||||
None => local_dir_path.push(dir.name.as_str()),
|
||||
}
|
||||
// Create directory on local
|
||||
match self
|
||||
.context
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.local
|
||||
.mkdir_ex(local_dir_path.as_path(), true)
|
||||
{
|
||||
match self.host.mkdir_ex(local_dir_path.as_path(), true) {
|
||||
Ok(_) => {
|
||||
// Apply file mode to directory
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
if let Some(pex) = dir.unix_pex {
|
||||
if let Err(err) = self
|
||||
.context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.local
|
||||
.chmod(local_dir_path.as_path(), pex)
|
||||
{
|
||||
if let Err(err) = self.host.chmod(local_dir_path.as_path(), pex) {
|
||||
self.log(
|
||||
LogLevel::Error,
|
||||
format!(
|
||||
@@ -464,13 +445,7 @@ impl FileTransferActivity {
|
||||
) -> Result<(), TransferErrorReason> {
|
||||
// Upload file
|
||||
// Try to open local file
|
||||
match self
|
||||
.context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.local
|
||||
.open_file_read(local.abs_path.as_path())
|
||||
{
|
||||
match self.host.open_file_read(local.abs_path.as_path()) {
|
||||
Ok(mut fhnd) => match self.client.send_file(local, remote) {
|
||||
Ok(mut rhnd) => {
|
||||
// Write file
|
||||
@@ -580,7 +555,7 @@ impl FileTransferActivity {
|
||||
file_name: String,
|
||||
) -> Result<(), TransferErrorReason> {
|
||||
// Try to open local file
|
||||
match self.context.as_ref().unwrap().local.open_file_write(local) {
|
||||
match self.host.open_file_write(local) {
|
||||
Ok(mut local_file) => {
|
||||
// Download file from remote
|
||||
match self.client.recv_file(remote) {
|
||||
@@ -657,8 +632,7 @@ impl FileTransferActivity {
|
||||
// Apply file mode to file
|
||||
#[cfg(any(target_os = "unix", target_os = "macos", target_os = "linux"))]
|
||||
if let Some(pex) = remote.unix_pex {
|
||||
if let Err(err) = self.context.as_ref().unwrap().local.chmod(local, pex)
|
||||
{
|
||||
if let Err(err) = self.host.chmod(local, pex) {
|
||||
self.log(
|
||||
LogLevel::Error,
|
||||
format!(
|
||||
@@ -696,7 +670,7 @@ impl FileTransferActivity {
|
||||
///
|
||||
/// Scan current local directory
|
||||
pub(super) fn local_scan(&mut self, path: &Path) {
|
||||
match self.context.as_ref().unwrap().local.scan_dir(path) {
|
||||
match self.host.scan_dir(path) {
|
||||
Ok(files) => {
|
||||
// Set files and sort (sorting is implicit)
|
||||
self.local.set_files(files);
|
||||
@@ -735,7 +709,7 @@ impl FileTransferActivity {
|
||||
// Get current directory
|
||||
let prev_dir: PathBuf = self.local.wrkdir.clone();
|
||||
// Change directory
|
||||
match self.context.as_mut().unwrap().local.change_wrkdir(path) {
|
||||
match self.host.change_wrkdir(path) {
|
||||
Ok(_) => {
|
||||
self.log(
|
||||
LogLevel::Info,
|
||||
@@ -858,8 +832,7 @@ impl FileTransferActivity {
|
||||
return Err(format!("Could not open file {}: {}", file.name, err));
|
||||
}
|
||||
// Get current file modification time
|
||||
let prev_mtime: SystemTime = match self.context.as_ref().unwrap().local.stat(tmpfile.path())
|
||||
{
|
||||
let prev_mtime: SystemTime = match self.host.stat(tmpfile.path()) {
|
||||
Ok(e) => e.get_last_change_time(),
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
@@ -874,8 +847,7 @@ impl FileTransferActivity {
|
||||
return Err(err);
|
||||
}
|
||||
// Get local fs entry
|
||||
let tmpfile_entry: FsEntry = match self.context.as_ref().unwrap().local.stat(tmpfile.path())
|
||||
{
|
||||
let tmpfile_entry: FsEntry = match self.host.stat(tmpfile.path()) {
|
||||
Ok(e) => e,
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
@@ -897,17 +869,16 @@ impl FileTransferActivity {
|
||||
.as_ref(),
|
||||
);
|
||||
// Get local fs entry
|
||||
let tmpfile_entry: FsEntry =
|
||||
match self.context.as_ref().unwrap().local.stat(tmpfile.path()) {
|
||||
Ok(e) => e,
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
"Could not stat \"{}\": {}",
|
||||
tmpfile.path().display(),
|
||||
err
|
||||
))
|
||||
}
|
||||
};
|
||||
let tmpfile_entry: FsEntry = match self.host.stat(tmpfile.path()) {
|
||||
Ok(e) => e,
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
"Could not stat \"{}\": {}",
|
||||
tmpfile.path().display(),
|
||||
err
|
||||
))
|
||||
}
|
||||
};
|
||||
// Write file
|
||||
let tmpfile_entry: &FsFile = match &tmpfile_entry {
|
||||
FsEntry::Directory(_) => panic!("tempfile is a directory for some reason"),
|
||||
|
||||
Reference in New Issue
Block a user