From 6768648ed2244abedeaf411a1d291fa9220115b8 Mon Sep 17 00:00:00 2001 From: vkill Date: Sun, 20 Nov 2022 19:09:35 +0800 Subject: [PATCH] Add methods to sftp::File --- async-ssh2-lite/src/sftp.rs | 25 +++++++++++++++++++ .../tests/integration_tests/sftp.rs | 8 ++++++ 2 files changed, 33 insertions(+) diff --git a/async-ssh2-lite/src/sftp.rs b/async-ssh2-lite/src/sftp.rs index 4fd1d6e..a0b3885 100644 --- a/async-ssh2-lite/src/sftp.rs +++ b/async-ssh2-lite/src/sftp.rs @@ -206,11 +206,36 @@ impl AsyncFile where S: AsyncSessionStream + Send + Sync + 'static, { + pub async fn setstat(&mut self, stat: FileStat) -> Result<(), Error> { + self.stream + .rw_with(|| self.inner.setstat(stat.clone()), &self.sess) + .await + } + + pub async fn stat(&mut self) -> Result { + self.stream.rw_with(|| self.inner.stat(), &self.sess).await + } + + pub async fn statvfs(&mut self) -> Result { + self.stream + .rw_with(|| self.inner.statvfs(), &self.sess) + .await + } + pub async fn readdir(&mut self) -> Result<(PathBuf, FileStat), Error> { self.stream .rw_with(|| self.inner.readdir(), &self.sess) .await } + + pub async fn fsync(&mut self) -> Result<(), Error> { + self.stream.rw_with(|| self.inner.fsync(), &self.sess).await + } + + #[doc(hidden)] + pub async fn close(&mut self) -> Result<(), Error> { + self.stream.rw_with(|| self.inner.close(), &self.sess).await + } } mod impl_futures_util { diff --git a/async-ssh2-lite/tests/integration_tests/sftp.rs b/async-ssh2-lite/tests/integration_tests/sftp.rs index c27ce75..0ea1384 100644 --- a/async-ssh2-lite/tests/integration_tests/sftp.rs +++ b/async-ssh2-lite/tests/integration_tests/sftp.rs @@ -43,8 +43,16 @@ async fn __run__session__sftp( let remote_path = PathBuf::from("/tmp").join(format!("sftp_{}", Uuid::new_v4())); sftp.create(&remote_path).await?; + let file_stat = sftp.stat(&remote_path).await?; println!("sftp file_stat:{:?}", file_stat); + + let mut sftp_file = sftp.open(&remote_path).await?; + let file_stat_for_file = sftp_file.stat().await?; + println!("sftp file_stat_for_file:{:?}", file_stat_for_file); + sftp_file.close().await?; + assert_eq!(file_stat, file_stat_for_file); + sftp.unlink(&remote_path).await?; let list = sftp.readdir(&PathBuf::from("/")).await?;