Skip to content

Commit

Permalink
Head should throw error on directory (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman authored Sep 28, 2024
1 parent 2fe97d3 commit edf5454
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ impl ObjectStore for HdfsObjectStore {
.await
.to_object_store_err()?;

if status.isdir {
return Err(HdfsError::IsADirectoryError(
"Head must be called on a file".to_string(),
))
.to_object_store_err();
}

Ok(ObjectMeta {
location: location.clone(),
last_modified: DateTime::<Utc>::from_timestamp(status.modification_time as i64, 0)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mod test {
file.write(buf.freeze()).await.unwrap();
file.close().await.unwrap();

client.mkdirs("/testdir", 0o755, true).await.unwrap();

let store = HdfsObjectStore::new(Arc::new(client));

test_object_store_head(&store).await?;
Expand All @@ -51,6 +53,7 @@ mod test {
assert_eq!(head.size, TEST_FILE_INTS * 4);

assert!(store.head(&Path::from("/testfile2")).await.is_err());
assert!(store.head(&Path::from("/testdir")).await.is_err());

Ok(())
}
Expand Down

0 comments on commit edf5454

Please sign in to comment.