ssh: split FileWrap out
This commit is contained in:
1 parent
e8b83b29c9
commit
65eaa44b0d
4 files changed
+64
-62
No files matched your search
@@ -0,0 +1,60 @@
|
||||
use crate::sftp::{Metadata, SftpChannelError, SftpChannelResult};
|
||||
use camino::Utf8PathBuf;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
pub(crate) enum FileWrap {
|
||||
Ssh2(ssh2::File),
|
||||
}
|
||||
|
||||
impl FileWrap {
|
||||
pub fn reader(&mut self) -> impl std::io::Read + '_ {
|
||||
match self {
|
||||
Self::Ssh2(file) => file,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn writer(&mut self) -> impl std::io::Write + '_ {
|
||||
match self {
|
||||
Self::Ssh2(file) => file,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_metadata(&mut self, metadata: Metadata) -> SftpChannelResult<()> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file
|
||||
.setstat(metadata.into())
|
||||
.map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&mut self) -> SftpChannelResult<Metadata> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file
|
||||
.stat()
|
||||
.map(Metadata::from)
|
||||
.map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_dir(&mut self) -> SftpChannelResult<(Utf8PathBuf, Metadata)> {
|
||||
match self {
|
||||
Self::Ssh2(file) => {
|
||||
file.readdir()
|
||||
.map_err(SftpChannelError::from)
|
||||
.and_then(|(path, stat)| match Utf8PathBuf::try_from(path) {
|
||||
Ok(path) => Ok((path, Metadata::from(stat))),
|
||||
Err(x) => Err(SftpChannelError::from(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidData,
|
||||
x,
|
||||
))),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fsync(&mut self) -> SftpChannelResult<()> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file.fsync().map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
mod auth;
|
||||
mod channelwrap;
|
||||
mod config;
|
||||
mod filewrap;
|
||||
mod host;
|
||||
mod pty;
|
||||
mod session;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::config::ConfigMap;
|
||||
use crate::filewrap::FileWrap;
|
||||
use crate::pty::*;
|
||||
use crate::session::{
|
||||
ChannelWrap, Exec, ExecResult, FileWrap, SessionEvent, SessionRequest, SessionWrap,
|
||||
SignalChannel,
|
||||
ChannelWrap, Exec, ExecResult, SessionEvent, SessionRequest, SessionWrap, SignalChannel,
|
||||
};
|
||||
use crate::sftp::{
|
||||
self, File, FileId, FileRequest, Metadata, SftpChannelError, SftpChannelResult, SftpRequest,
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::config::ConfigMap;
|
||||
use crate::host::*;
|
||||
use crate::pty::*;
|
||||
pub(crate) use crate::session::inner::*;
|
||||
use crate::sftp::{Metadata, Sftp, SftpChannelError, SftpChannelResult, SftpRequest};
|
||||
use camino::Utf8PathBuf;
|
||||
use crate::sftp::{Sftp, SftpRequest};
|
||||
use filedescriptor::{
|
||||
socketpair, AsRawSocketDescriptor, FileDescriptor, SocketDescriptor, POLLIN, POLLOUT,
|
||||
};
|
||||
@@ -14,7 +13,6 @@ use portable_pty::PtySize;
|
||||
use smol::channel::{bounded, Receiver, Sender};
|
||||
use ssh2::BlockDirections;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::io::Write;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -76,63 +74,6 @@ pub(crate) struct Exec {
|
||||
pub reply: Sender<ExecResult>,
|
||||
}
|
||||
|
||||
pub(crate) enum FileWrap {
|
||||
Ssh2(ssh2::File),
|
||||
}
|
||||
|
||||
impl FileWrap {
|
||||
pub fn reader(&mut self) -> impl std::io::Read + '_ {
|
||||
match self {
|
||||
Self::Ssh2(file) => file,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn writer(&mut self) -> impl std::io::Write + '_ {
|
||||
match self {
|
||||
Self::Ssh2(file) => file,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_metadata(&mut self, metadata: Metadata) -> SftpChannelResult<()> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file
|
||||
.setstat(metadata.into())
|
||||
.map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&mut self) -> SftpChannelResult<Metadata> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file
|
||||
.stat()
|
||||
.map(Metadata::from)
|
||||
.map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_dir(&mut self) -> SftpChannelResult<(Utf8PathBuf, Metadata)> {
|
||||
match self {
|
||||
Self::Ssh2(file) => {
|
||||
file.readdir()
|
||||
.map_err(SftpChannelError::from)
|
||||
.and_then(|(path, stat)| match Utf8PathBuf::try_from(path) {
|
||||
Ok(path) => Ok((path, Metadata::from(stat))),
|
||||
Err(x) => Err(SftpChannelError::from(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidData,
|
||||
x,
|
||||
))),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fsync(&mut self) -> SftpChannelResult<()> {
|
||||
match self {
|
||||
Self::Ssh2(file) => file.fsync().map_err(SftpChannelError::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Ssh2Session {
|
||||
sess: ssh2::Session,
|
||||
sftp: Option<ssh2::Sftp>,
|
||||
|
||||
Reference in new issue
Block a user