Skip to content
Clone

fix(storage): treat a missing object as absent in exists()

HEAD on a non-existent key surfaces as HttpFailWithBody(404/403) from

rust-s3, so every LFS "is this object already uploaded" probe turned
into an error instead of a false answer.
ZhenYi committed
parent 001c5fe commit 25e4ac6 Browse files

1 file changed

+9 −2

Modified lib/storage/src/s3.rs View lib/storage/src/s3.rs
@@ -282,9 +282,16 @@
282282 }
283283 }
284284
285 /// Whether a key is present. A missing key is a `false`, not an error: the
286 /// underlying `HEAD` answers 404, which rust-s3 surfaces as a failure, and
287 /// callers use this to choose between "create" and "already there".
285288 pub async fn exists(&self, key: &str) -> Result<bool, StorageError> {
286 let (_, status) = self.bucket.head_object(key).await?;
287 Ok((200..300).contains(&status))
289 match self.bucket.head_object(key).await {
290 Ok((_, status)) => Ok((200..300).contains(&status)),
291 Err(s3::error::S3Error::HttpFailWithBody(404, _))
292 | Err(s3::error::S3Error::HttpFailWithBody(403, _)) => Ok(false),
293 Err(err) => Err(StorageError::S3(err)),
294 }
288295 }
289296
290297 pub async fn head(&self, key: &str) -> Result<Option<(u64, String)>, StorageError> {