fix: non-existing object delete response

The expected response code for deleting non-existing objects is
expected to be 204 (No Content) instead of NoSuchKey. The tests
are updated to validate expected responses.

Fixes #724
This commit is contained in:
Ben McClelland
2024-08-08 11:46:36 -07:00
parent adbc8140ed
commit e92b36a12c
2 changed files with 13 additions and 21 deletions
+7 -2
View File
@@ -1527,13 +1527,18 @@ func (p *Posix) DeleteObject(_ context.Context, input *s3.DeleteObjectInput) err
fi, err := os.Stat(objpath)
if errors.Is(err, fs.ErrNotExist) {
return s3err.GetAPIError(s3err.ErrNoSuchKey)
// AWS returns success if the object does not exist
return nil
}
if err != nil {
return fmt.Errorf("stat object: %w", err)
}
if strings.HasSuffix(object, "/") && !fi.IsDir() {
return s3err.GetAPIError(s3err.ErrNoSuchKey)
// requested object is expecting a directory with a trailing
// slash, but the object is not a directory. treat this as
// a non-existent object.
// AWS returns success if the object does not exist
return nil
}
err = os.Remove(objpath)