opendal/services/hdfs/
delete.rs1use super::backend::HdfsBackend;
19use crate::raw::*;
20use crate::*;
21use std::io;
22use std::sync::Arc;
23
24pub struct HdfsDeleter {
25 core: Arc<HdfsBackend>,
26}
27
28impl HdfsDeleter {
29 pub fn new(core: Arc<HdfsBackend>) -> Self {
30 Self { core }
31 }
32}
33
34impl oio::OneShotDelete for HdfsDeleter {
35 async fn delete_once(&self, path: String, _: OpDelete) -> Result<()> {
36 let p = build_rooted_abs_path(&self.core.root, &path);
37
38 let meta = self.core.client.metadata(&p);
39
40 if let Err(err) = meta {
41 return if err.kind() == io::ErrorKind::NotFound {
42 Ok(())
43 } else {
44 Err(new_std_io_error(err))
45 };
46 }
47
48 let meta = meta.ok().unwrap();
50
51 let result = if meta.is_dir() {
52 self.core.client.remove_dir(&p)
53 } else {
54 self.core.client.remove_file(&p)
55 };
56
57 result.map_err(new_std_io_error)?;
58
59 Ok(())
60 }
61}
62
63impl oio::BlockingOneShotDelete for HdfsDeleter {
64 fn blocking_delete_once(&self, path: String, _: OpDelete) -> Result<()> {
65 let p = build_rooted_abs_path(&self.core.root, &path);
66
67 let meta = self.core.client.metadata(&p);
68
69 if let Err(err) = meta {
70 return if err.kind() == io::ErrorKind::NotFound {
71 Ok(())
72 } else {
73 Err(new_std_io_error(err))
74 };
75 }
76
77 let meta = meta.ok().unwrap();
79
80 let result = if meta.is_dir() {
81 self.core.client.remove_dir(&p)
82 } else {
83 self.core.client.remove_file(&p)
84 };
85
86 result.map_err(new_std_io_error)?;
87
88 Ok(())
89 }
90}