2024-04-29 06:23:42 -07:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2024-12-19 19:23:27 -08:00
|
|
|
"slices"
|
2024-04-29 06:23:42 -07:00
|
|
|
"strings"
|
|
|
|
|
2025-02-08 02:26:39 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
|
|
|
2024-04-29 06:23:42 -07:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
|
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
2025-01-26 09:25:06 +03:30
|
|
|
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
2024-04-29 06:23:42 -07:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
deleteMultipleObjectsLimit = 1000
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
bucket, object := s3_constants.GetBucketAndObject(r)
|
|
|
|
glog.V(3).Infof("DeleteObjectHandler %s %s", bucket, object)
|
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
// Check for specific version ID in query parameters
|
|
|
|
versionId := r.URL.Query().Get("versionId")
|
2024-04-29 06:23:42 -07:00
|
|
|
|
2025-07-21 00:23:22 -07:00
|
|
|
// Get detailed versioning state for proper handling of suspended vs enabled versioning
|
|
|
|
versioningState, err := s3a.getVersioningState(bucket)
|
2025-07-09 01:51:45 -07:00
|
|
|
if err != nil {
|
|
|
|
if err == filer_pb.ErrNotFound {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
glog.Errorf("Error checking versioning status for bucket %s: %v", bucket, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
2025-03-18 19:01:54 +07:00
|
|
|
|
2025-07-21 00:23:22 -07:00
|
|
|
versioningEnabled := (versioningState == s3_constants.VersioningEnabled)
|
|
|
|
versioningSuspended := (versioningState == s3_constants.VersioningSuspended)
|
|
|
|
versioningConfigured := (versioningState != "")
|
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
var auditLog *s3err.AccessLog
|
2025-03-18 19:01:54 +07:00
|
|
|
if s3err.Logger != nil {
|
|
|
|
auditLog = s3err.GetAccessLog(r, http.StatusNoContent, s3err.ErrNone)
|
|
|
|
}
|
|
|
|
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
if versioningConfigured {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Handle versioned delete based on specific versioning state
|
2025-07-09 01:51:45 -07:00
|
|
|
if versionId != "" {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Delete specific version (same for both enabled and suspended)
|
2025-07-18 22:25:58 -07:00
|
|
|
// Check object lock permissions before deleting specific version
|
|
|
|
governanceBypassAllowed := s3a.evaluateGovernanceBypassRequest(r, bucket, object)
|
|
|
|
if err := s3a.enforceObjectLockProtections(r, bucket, object, versionId, governanceBypassAllowed); err != nil {
|
|
|
|
glog.V(2).Infof("DeleteObjectHandler: object lock check failed for %s/%s: %v", bucket, object, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrAccessDenied)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
// Delete specific version
|
|
|
|
err := s3a.deleteSpecificObjectVersion(bucket, object, versionId)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Failed to delete specific version %s: %v", versionId, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
2024-04-29 06:25:06 -07:00
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
// Set version ID in response header
|
|
|
|
w.Header().Set("x-amz-version-id", versionId)
|
|
|
|
} else {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Delete without version ID - behavior depends on versioning state
|
|
|
|
if versioningEnabled {
|
|
|
|
// Enabled versioning: Create delete marker (logical delete)
|
|
|
|
// AWS S3 behavior: Delete marker creation is NOT blocked by object retention
|
|
|
|
// because it's a logical delete that doesn't actually remove the retained version
|
|
|
|
deleteMarkerVersionId, err := s3a.createDeleteMarker(bucket, object)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Failed to create delete marker: %v", err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set delete marker version ID in response header
|
|
|
|
w.Header().Set("x-amz-version-id", deleteMarkerVersionId)
|
|
|
|
w.Header().Set("x-amz-delete-marker", "true")
|
|
|
|
} else if versioningSuspended {
|
|
|
|
// Suspended versioning: Actually delete the "null" version object
|
|
|
|
glog.V(2).Infof("DeleteObjectHandler: deleting null version for suspended versioning %s/%s", bucket, object)
|
|
|
|
|
|
|
|
// Check object lock permissions before deleting "null" version
|
|
|
|
governanceBypassAllowed := s3a.evaluateGovernanceBypassRequest(r, bucket, object)
|
|
|
|
if err := s3a.enforceObjectLockProtections(r, bucket, object, "null", governanceBypassAllowed); err != nil {
|
|
|
|
glog.V(2).Infof("DeleteObjectHandler: object lock check failed for %s/%s: %v", bucket, object, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrAccessDenied)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the "null" version (the regular file)
|
|
|
|
err := s3a.deleteSpecificObjectVersion(bucket, object, "null")
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Failed to delete null version: %v", err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
2024-04-29 06:25:06 -07:00
|
|
|
|
2025-07-21 00:23:22 -07:00
|
|
|
// Note: According to AWS S3 spec, suspended versioning should NOT return version ID headers
|
|
|
|
// The object is deleted but no version information is returned
|
|
|
|
}
|
2025-03-18 19:01:54 +07:00
|
|
|
}
|
2025-07-09 01:51:45 -07:00
|
|
|
} else {
|
|
|
|
// Handle regular delete (non-versioned)
|
2025-07-18 22:25:58 -07:00
|
|
|
// Check object lock permissions before deleting object
|
|
|
|
governanceBypassAllowed := s3a.evaluateGovernanceBypassRequest(r, bucket, object)
|
|
|
|
if err := s3a.enforceObjectLockProtections(r, bucket, object, "", governanceBypassAllowed); err != nil {
|
|
|
|
glog.V(2).Infof("DeleteObjectHandler: object lock check failed for %s/%s: %v", bucket, object, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrAccessDenied)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
target := util.FullPath(fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, bucket, object))
|
|
|
|
dir, name := target.DirAndName()
|
2025-03-18 19:01:54 +07:00
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
|
|
|
|
if err := doDeleteEntry(client, dir, name, true, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-04-29 06:25:06 -07:00
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
if s3a.option.AllowEmptyFolder {
|
|
|
|
return nil
|
2024-04-29 06:25:06 -07:00
|
|
|
}
|
2025-07-09 01:51:45 -07:00
|
|
|
|
|
|
|
directoriesWithDeletion := make(map[string]int)
|
|
|
|
if strings.LastIndex(object, "/") > 0 {
|
|
|
|
directoriesWithDeletion[dir]++
|
|
|
|
// purge empty folders, only checking folders with deletions
|
|
|
|
for len(directoriesWithDeletion) > 0 {
|
|
|
|
directoriesWithDeletion = s3a.doDeleteEmptyDirectories(client, directoriesWithDeletion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
2024-04-29 06:23:42 -07:00
|
|
|
}
|
2025-07-09 01:51:45 -07:00
|
|
|
}
|
2024-04-29 06:25:06 -07:00
|
|
|
|
2025-07-09 01:51:45 -07:00
|
|
|
if auditLog != nil {
|
|
|
|
auditLog.Key = strings.TrimPrefix(object, "/")
|
|
|
|
s3err.PostAccessLog(*auditLog)
|
2024-07-10 20:47:43 +05:00
|
|
|
}
|
2024-04-29 06:25:06 -07:00
|
|
|
|
2025-02-08 02:26:39 +08:00
|
|
|
stats_collect.RecordBucketActiveTime(bucket)
|
2025-01-26 09:25:06 +03:30
|
|
|
stats_collect.S3DeletedObjectsCounter.WithLabelValues(bucket).Inc()
|
2024-04-29 06:25:06 -07:00
|
|
|
w.WriteHeader(http.StatusNoContent)
|
2024-04-29 06:23:42 -07:00
|
|
|
}
|
|
|
|
|
2025-07-12 21:58:55 -07:00
|
|
|
// ObjectIdentifier represents an object to be deleted with its key name and optional version ID.
|
2024-04-29 06:23:42 -07:00
|
|
|
type ObjectIdentifier struct {
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
Key string `xml:"Key"`
|
|
|
|
VersionId string `xml:"VersionId,omitempty"`
|
|
|
|
DeleteMarker bool `xml:"DeleteMarker,omitempty"`
|
|
|
|
DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId,omitempty"`
|
2024-04-29 06:23:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObjectsRequest - xml carrying the object key names which needs to be deleted.
|
|
|
|
type DeleteObjectsRequest struct {
|
|
|
|
// Element to enable quiet mode for the request
|
|
|
|
Quiet bool
|
|
|
|
// List of objects to be deleted
|
|
|
|
Objects []ObjectIdentifier `xml:"Object"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteError structure.
|
|
|
|
type DeleteError struct {
|
2025-07-12 21:58:55 -07:00
|
|
|
Code string `xml:"Code"`
|
|
|
|
Message string `xml:"Message"`
|
|
|
|
Key string `xml:"Key"`
|
|
|
|
VersionId string `xml:"VersionId,omitempty"`
|
2024-04-29 06:23:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObjectsResponse container for multiple object deletes.
|
|
|
|
type DeleteObjectsResponse struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ DeleteResult" json:"-"`
|
|
|
|
|
|
|
|
// Collection of all deleted objects
|
|
|
|
DeletedObjects []ObjectIdentifier `xml:"Deleted,omitempty"`
|
|
|
|
|
|
|
|
// Collection of errors deleting certain objects.
|
|
|
|
Errors []DeleteError `xml:"Error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMultipleObjectsHandler - Delete multiple objects
|
|
|
|
func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
bucket, _ := s3_constants.GetBucketAndObject(r)
|
|
|
|
glog.V(3).Infof("DeleteMultipleObjectsHandler %s", bucket)
|
|
|
|
|
|
|
|
deleteXMLBytes, err := io.ReadAll(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteObjects := &DeleteObjectsRequest{}
|
|
|
|
if err := xml.Unmarshal(deleteXMLBytes, deleteObjects); err != nil {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(deleteObjects.Objects) > deleteMultipleObjectsLimit {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxDeleteObjects)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var deletedObjects []ObjectIdentifier
|
|
|
|
var deleteErrors []DeleteError
|
|
|
|
var auditLog *s3err.AccessLog
|
|
|
|
|
|
|
|
directoriesWithDeletion := make(map[string]int)
|
|
|
|
|
|
|
|
if s3err.Logger != nil {
|
|
|
|
auditLog = s3err.GetAccessLog(r, http.StatusNoContent, s3err.ErrNone)
|
|
|
|
}
|
2025-07-12 21:58:55 -07:00
|
|
|
|
2025-07-21 00:23:22 -07:00
|
|
|
// Get detailed versioning state for proper handling of suspended vs enabled versioning
|
|
|
|
versioningState, err := s3a.getVersioningState(bucket)
|
2025-07-12 21:58:55 -07:00
|
|
|
if err != nil {
|
|
|
|
if err == filer_pb.ErrNotFound {
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
glog.Errorf("Error checking versioning status for bucket %s: %v", bucket, err)
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-07-21 00:23:22 -07:00
|
|
|
versioningEnabled := (versioningState == s3_constants.VersioningEnabled)
|
|
|
|
versioningSuspended := (versioningState == s3_constants.VersioningSuspended)
|
|
|
|
versioningConfigured := (versioningState != "")
|
|
|
|
|
2024-04-29 06:23:42 -07:00
|
|
|
s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
|
|
|
|
// delete file entries
|
|
|
|
for _, object := range deleteObjects.Objects {
|
2025-07-12 21:58:55 -07:00
|
|
|
if object.Key == "" {
|
2024-04-29 06:23:42 -07:00
|
|
|
continue
|
|
|
|
}
|
2025-07-12 21:58:55 -07:00
|
|
|
|
|
|
|
// Check object lock permissions before deletion (only for versioned buckets)
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
if versioningConfigured {
|
2025-07-18 22:25:58 -07:00
|
|
|
// Validate governance bypass for this specific object
|
|
|
|
governanceBypassAllowed := s3a.evaluateGovernanceBypassRequest(r, bucket, object.Key)
|
|
|
|
if err := s3a.enforceObjectLockProtections(r, bucket, object.Key, object.VersionId, governanceBypassAllowed); err != nil {
|
2025-07-12 21:58:55 -07:00
|
|
|
glog.V(2).Infof("DeleteMultipleObjectsHandler: object lock check failed for %s/%s (version: %s): %v", bucket, object.Key, object.VersionId, err)
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{
|
|
|
|
Code: s3err.GetAPIError(s3err.ErrAccessDenied).Code,
|
|
|
|
Message: s3err.GetAPIError(s3err.ErrAccessDenied).Description,
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: object.VersionId,
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
|
|
|
|
var deleteVersionId string
|
|
|
|
var isDeleteMarker bool
|
|
|
|
|
|
|
|
if versioningConfigured {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Handle versioned delete based on specific versioning state
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
if object.VersionId != "" {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Delete specific version (same for both enabled and suspended)
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
err := s3a.deleteSpecificObjectVersion(bucket, object.Key, object.VersionId)
|
|
|
|
if err != nil {
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{
|
|
|
|
Code: "",
|
|
|
|
Message: err.Error(),
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: object.VersionId,
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleteVersionId = object.VersionId
|
|
|
|
} else {
|
2025-07-21 00:23:22 -07:00
|
|
|
// Delete without version ID - behavior depends on versioning state
|
|
|
|
if versioningEnabled {
|
|
|
|
// Enabled versioning: Create delete marker (logical delete)
|
|
|
|
deleteMarkerVersionId, err := s3a.createDeleteMarker(bucket, object.Key)
|
|
|
|
if err != nil {
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{
|
|
|
|
Code: "",
|
|
|
|
Message: err.Error(),
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: object.VersionId,
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleteVersionId = deleteMarkerVersionId
|
|
|
|
isDeleteMarker = true
|
|
|
|
} else if versioningSuspended {
|
|
|
|
// Suspended versioning: Actually delete the "null" version object
|
|
|
|
glog.V(2).Infof("DeleteMultipleObjectsHandler: deleting null version for suspended versioning %s/%s", bucket, object.Key)
|
|
|
|
|
|
|
|
err := s3a.deleteSpecificObjectVersion(bucket, object.Key, "null")
|
|
|
|
if err != nil {
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{
|
|
|
|
Code: "",
|
|
|
|
Message: err.Error(),
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: "null",
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleteVersionId = "null"
|
|
|
|
// Note: For suspended versioning, we don't set isDeleteMarker=true
|
|
|
|
// because we actually deleted the object, not created a delete marker
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to successful deletions with version info
|
|
|
|
deletedObject := ObjectIdentifier{
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: deleteVersionId,
|
|
|
|
DeleteMarker: isDeleteMarker,
|
|
|
|
}
|
|
|
|
|
|
|
|
// For delete markers, also set DeleteMarkerVersionId field
|
|
|
|
if isDeleteMarker {
|
|
|
|
deletedObject.DeleteMarkerVersionId = deleteVersionId
|
|
|
|
// Don't set VersionId for delete markers, use DeleteMarkerVersionId instead
|
|
|
|
deletedObject.VersionId = ""
|
|
|
|
}
|
|
|
|
if !deleteObjects.Quiet {
|
|
|
|
deletedObjects = append(deletedObjects, deletedObject)
|
|
|
|
}
|
|
|
|
if isDeleteMarker {
|
|
|
|
// For delete markers, we don't need to track directories for cleanup
|
|
|
|
continue
|
|
|
|
}
|
2024-04-29 06:23:42 -07:00
|
|
|
} else {
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
// Handle non-versioned delete (original logic)
|
|
|
|
lastSeparator := strings.LastIndex(object.Key, "/")
|
|
|
|
parentDirectoryPath, entryName, isDeleteData, isRecursive := "", object.Key, true, false
|
|
|
|
if lastSeparator > 0 && lastSeparator+1 < len(object.Key) {
|
|
|
|
entryName = object.Key[lastSeparator+1:]
|
|
|
|
parentDirectoryPath = "/" + object.Key[:lastSeparator]
|
|
|
|
}
|
|
|
|
parentDirectoryPath = fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, bucket, parentDirectoryPath)
|
|
|
|
|
|
|
|
err := doDeleteEntry(client, parentDirectoryPath, entryName, isDeleteData, isRecursive)
|
|
|
|
if err == nil {
|
|
|
|
directoriesWithDeletion[parentDirectoryPath]++
|
|
|
|
deletedObjects = append(deletedObjects, object)
|
|
|
|
} else if strings.Contains(err.Error(), filer.MsgFailDelNonEmptyFolder) {
|
|
|
|
deletedObjects = append(deletedObjects, object)
|
|
|
|
} else {
|
|
|
|
delete(directoriesWithDeletion, parentDirectoryPath)
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{
|
|
|
|
Code: "",
|
|
|
|
Message: err.Error(),
|
|
|
|
Key: object.Key,
|
|
|
|
VersionId: object.VersionId,
|
|
|
|
})
|
|
|
|
}
|
2024-04-29 06:23:42 -07:00
|
|
|
}
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
|
2024-04-29 06:23:42 -07:00
|
|
|
if auditLog != nil {
|
test versioning also (#7000)
* test versioning also
* fix some versioning tests
* fall back
* fixes
Never-versioned buckets: No VersionId headers, no Status field
Pre-versioning objects: Regular files, VersionId="null", included in all operations
Post-versioning objects: Stored in .versions directories with real version IDs
Suspended versioning: Proper status handling and null version IDs
* fixes
Bucket Versioning Status Compliance
Fixed: New buckets now return no Status field (AWS S3 compliant)
Before: Always returned "Suspended" ❌
After: Returns empty VersioningConfiguration for unconfigured buckets ✅
2. Multi-Object Delete Versioning Support
Fixed: DeleteMultipleObjectsHandler now fully versioning-aware
Before: Always deleted physical files, breaking versioning ❌
After: Creates delete markers or deletes specific versions properly ✅
Added: DeleteMarker field in response structure for AWS compatibility
3. Copy Operations Versioning Support
Fixed: CopyObjectHandler and CopyObjectPartHandler now versioning-aware
Before: Only copied regular files, couldn't handle versioned sources ❌
After: Parses version IDs from copy source, creates versions in destination ✅
Added: pathToBucketObjectAndVersion() function for version ID parsing
4. Pre-versioning Object Handling
Fixed: getLatestObjectVersion() now has proper fallback logic
Before: Failed when .versions directory didn't exist ❌
After: Falls back to regular objects for pre-versioning scenarios ✅
5. Enhanced Object Version Listings
Fixed: listObjectVersions() includes both versioned AND pre-versioning objects
Before: Only showed .versions directories, ignored pre-versioning objects ❌
After: Shows complete version history with VersionId="null" for pre-versioning ✅
6. Null Version ID Handling
Fixed: getSpecificObjectVersion() properly handles versionId="null"
Before: Couldn't retrieve pre-versioning objects by version ID ❌
After: Returns regular object files for "null" version requests ✅
7. Version ID Response Headers
Fixed: PUT operations only return x-amz-version-id when appropriate
Before: Returned version IDs for non-versioned buckets ❌
After: Only returns version IDs for explicitly configured versioning ✅
* more fixes
* fix copying with versioning, multipart upload
* more fixes
* reduce volume size for easier dev test
* fix
* fix version id
* fix versioning
* Update filer_multipart.go
* fix multipart versioned upload
* more fixes
* more fixes
* fix versioning on suspended
* fixes
* fixing test_versioning_obj_suspended_copy
* Update s3api_object_versioning.go
* fix versions
* skipping test_versioning_obj_suspend_versions
* > If the versioning state has never been set on a bucket, it has no versioning state; a GetBucketVersioning request does not return a versioning state value.
* fix tests, avoid duplicated bucket creation, skip tests
* only run s3tests_boto3/functional/test_s3.py
* fix checking filer_pb.ErrNotFound
* Update weed/s3api/s3api_object_versioning.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_object_handlers_copy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_config.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/versioning/s3_versioning_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-19 21:43:34 -07:00
|
|
|
auditLog.Key = object.Key
|
2024-04-29 06:23:42 -07:00
|
|
|
s3err.PostAccessLog(*auditLog)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-20 02:00:08 +00:00
|
|
|
if s3a.option.AllowEmptyFolder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-29 06:23:42 -07:00
|
|
|
// purge empty folders, only checking folders with deletions
|
|
|
|
for len(directoriesWithDeletion) > 0 {
|
|
|
|
directoriesWithDeletion = s3a.doDeleteEmptyDirectories(client, directoriesWithDeletion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
deleteResp := DeleteObjectsResponse{}
|
|
|
|
if !deleteObjects.Quiet {
|
|
|
|
deleteResp.DeletedObjects = deletedObjects
|
|
|
|
}
|
|
|
|
deleteResp.Errors = deleteErrors
|
2025-02-08 02:26:39 +08:00
|
|
|
stats_collect.RecordBucketActiveTime(bucket)
|
2025-01-26 09:25:06 +03:30
|
|
|
stats_collect.S3DeletedObjectsCounter.WithLabelValues(bucket).Add(float64(len(deletedObjects)))
|
2024-04-29 06:23:42 -07:00
|
|
|
|
|
|
|
writeSuccessResponseXML(w, r, deleteResp)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3a *S3ApiServer) doDeleteEmptyDirectories(client filer_pb.SeaweedFilerClient, directoriesWithDeletion map[string]int) (newDirectoriesWithDeletion map[string]int) {
|
|
|
|
var allDirs []string
|
|
|
|
for dir := range directoriesWithDeletion {
|
|
|
|
allDirs = append(allDirs, dir)
|
|
|
|
}
|
|
|
|
slices.SortFunc(allDirs, func(a, b string) int {
|
|
|
|
return len(b) - len(a)
|
|
|
|
})
|
|
|
|
newDirectoriesWithDeletion = make(map[string]int)
|
|
|
|
for _, dir := range allDirs {
|
|
|
|
parentDir, dirName := util.FullPath(dir).DirAndName()
|
|
|
|
if parentDir == s3a.option.BucketsPath {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := doDeleteEntry(client, parentDir, dirName, false, false); err != nil {
|
|
|
|
glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err)
|
|
|
|
} else {
|
|
|
|
newDirectoriesWithDeletion[parentDir]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|