Skip to content

Commit

Permalink
add src check
Browse files Browse the repository at this point in the history
  • Loading branch information
qingwen220 committed Nov 16, 2023
1 parent 3ce8838 commit e3f11cf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
57 changes: 38 additions & 19 deletions core/src/services/hdfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,41 @@ unsafe impl Sync for HdfsBackend {}

impl HdfsBackend {
fn create_parent_if_need(&self, path: &str) -> Result<()> {
if let Err(err) = self.client.metadata(path) {
// Early return if other error happened.
if err.kind() != io::ErrorKind::NotFound {
return Err(new_std_io_error(err));
}
let result = self.client.metadata(path);
match result {
Err(err) => {
// Early return if other error happened.
if err.kind() != io::ErrorKind::NotFound {
return Err(new_std_io_error(err));
}

let parent = PathBuf::from(path)
.parent()
.ok_or_else(|| {
Error::new(
ErrorKind::Unexpected,
"path should have parent but not, it must be malformed",
)
.with_context("input", path)
})?
.to_path_buf();

self.client
.create_dir(&parent.to_string_lossy())
.map_err(new_std_io_error)?;
let parent = PathBuf::from(path)
.parent()
.ok_or_else(|| {
Error::new(
ErrorKind::Unexpected,
"path should have parent but not, it must be malformed",
)
.with_context("input", path)
})?
.to_path_buf();

self.client
.create_dir(&parent.to_string_lossy())
.map_err(new_std_io_error)?;
}
Ok(metadata) => {
if metadata.is_file() {
self.client
.remove_file(&path)
.map_err(new_std_io_error)?;
} else {
return Err(Error::new(
ErrorKind::IsADirectory,
"path should be a file")
.with_context("input", path))
}
}
}

Ok(())
Expand Down Expand Up @@ -281,6 +296,8 @@ impl Accessor for HdfsBackend {

async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
let from_path = build_rooted_abs_path(&self.root, from);
self.client.metadata(&from_path).map_err(new_std_io_error)?;

let to_path = build_rooted_abs_path(&self.root, to);
self.create_parent_if_need(&to_path)?;

Expand Down Expand Up @@ -410,6 +427,8 @@ impl Accessor for HdfsBackend {

fn blocking_rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
let from_path = build_rooted_abs_path(&self.root, from);
self.client.metadata(&from_path).map_err(new_std_io_error)?;

let to_path = build_rooted_abs_path(&self.root, to);
self.create_parent_if_need(&to_path)?;

Expand Down
4 changes: 2 additions & 2 deletions core/src/services/hdfs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ This service can be used to:
- [x] create_dir
- [x] delete
- [ ] copy
- [ ] rename
- [x] rename
- [x] list
- [ ] ~~scan~~
- [ ] ~~presign~~
- [x] blocking
- [x] append
- [ ] append

## Differences with webhdfs

Expand Down

0 comments on commit e3f11cf

Please sign in to comment.