use std::sync::Arc;
use super::core::SftpCore;
use super::error::is_not_found;
use super::error::parse_sftp_error;
use opendal_core::raw::*;
use opendal_core::*;
pub struct SftpDeleter {
core: Arc<SftpCore>,
}
impl SftpDeleter {
pub fn new(core: Arc<SftpCore>) -> Self {
Self { core }
}
}
impl oio::OneShotDelete for SftpDeleter {
async fn delete_once(&self, path: String, _: OpDelete) -> Result<()> {
let client = self.core.connect().await?;
let mut fs = client.fs();
fs.set_cwd(&self.core.root);
let res = if path.ends_with('/') {
fs.remove_dir(path).await
} else {
fs.remove_file(path).await
};
match res {
Ok(()) => Ok(()),
Err(e) if is_not_found(&e) => Ok(()),
Err(e) => Err(parse_sftp_error(e)),
}
}
}