Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion object_store/src/azure/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,19 @@ impl AzureClient {
path: path.as_ref(),
})?;

Ok(response)
match response.headers().get("x-ms-resource-type") {
Some(resource) if resource.as_ref() != b"file" => {
Err(crate::Error::NotFound {
path: path.to_string(),
source: format!(
"Not a directory, got x-ms-resource-type: {}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be, "Not a file"?

Copy link
Contributor Author

@tustvold tustvold May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops lol

Edit: fixed, good spot

String::from_utf8_lossy(resource.as_ref())
)
.into(),
})
}
_ => Ok(response),
}
}

/// Make an Azure Delete request <https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob>
Expand Down
8 changes: 8 additions & 0 deletions object_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,14 @@ mod tests {
assert_eq!(result.common_prefixes.len(), 1);
assert_eq!(result.common_prefixes[0], Path::from("test_dir"));

// Should return not found
let err = storage.get(&Path::from("test_dir")).await.unwrap_err();
assert!(matches!(err, crate::Error::NotFound { .. }), "{}", err);

// Should return not found
let err = storage.head(&Path::from("test_dir")).await.unwrap_err();
assert!(matches!(err, crate::Error::NotFound { .. }), "{}", err);

// List everything starting with a prefix that should return results
let prefix = Path::from("test_dir");
let content_list = flatten_list_stream(storage, Some(&prefix)).await.unwrap();
Expand Down
43 changes: 27 additions & 16 deletions object_store/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,23 @@ impl ObjectStore for LocalFileSystem {

maybe_spawn_blocking(move || {
let metadata = match metadata(&path) {
Err(e) => Err(if e.kind() == ErrorKind::NotFound {
Error::NotFound {
Err(e) => Err(match e.kind() {
ErrorKind::NotFound => Error::NotFound {
path: path.clone(),
source: e,
}
} else {
Error::Metadata {
},
_ => Error::Metadata {
source: e.into(),
path: location.to_string(),
}
},
}),
Ok(m) => Ok(m),
Ok(m) => match m.is_file() {
true => Ok(m),
false => Err(Error::NotFound {
path,
source: io::Error::new(ErrorKind::NotFound, "is not file"),
}),
},
}?;
convert_metadata(metadata, location)
})
Expand Down Expand Up @@ -878,19 +883,25 @@ fn read_range(file: &mut File, path: &PathBuf, range: Range<usize>) -> Result<By
}

fn open_file(path: &PathBuf) -> Result<File> {
let file = File::open(path).map_err(|e| {
if e.kind() == std::io::ErrorKind::NotFound {
Error::NotFound {
let file = match File::open(path).and_then(|f| Ok((f.metadata()?, f))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially slightly unfortunate, in that we require an additional syscall, but I couldn't find a mechanism to only open files

Err(e) => Err(match e.kind() {
ErrorKind::NotFound => Error::NotFound {
path: path.clone(),
source: e,
}
} else {
Error::UnableToOpenFile {
},
_ => Error::UnableToOpenFile {
path: path.clone(),
source: e,
}
}
})?;
},
}),
Ok((metadata, file)) => match metadata.is_file() {
true => Ok(file),
false => Err(Error::NotFound {
path: path.clone(),
source: io::Error::new(ErrorKind::NotFound, "not a file"),
}),
},
}?;
Ok(file)
}

Expand Down