[server] Fix auto rename upload response with wrong id on conflict

This commit is contained in:
Abhishek Shroff
2026-02-11 06:08:23 +05:30
parent a39c66a9c2
commit dc59dd0709
3 changed files with 27 additions and 7 deletions

View File

@@ -41,6 +41,10 @@ func handleUploadRequest(c *gin.Context) {
panic(err)
}
}
// Needed to be able to retreive the created resource
if id == uuid.Nil {
id, _ = uuid.NewV7()
}
// TODO: Calculate and verify sha sum
@@ -77,7 +81,13 @@ func handleUploadRequest(c *gin.Context) {
}
// id may have changed if this is an overwrite
r, err := f.ResourceByPathWithRoot(params.Path)
var r core.Resource
if params.Conflict == core.ResourceBindConflictResolutionOverwrite || params.Conflict == core.ResourceBindConflictResolutionDelete {
r, err = f.ResourceByPathWithRoot(params.Path)
} else {
r, err = f.ResourceByID(id)
}
if err != nil {
panic(err)
}

View File

@@ -180,6 +180,10 @@ func handlePartialUploadsFinalizeRequest(c *gin.Context) {
}
}
if resourceID == uuid.Nil {
resourceID, _ = uuid.NewV7()
}
f := authenticator.GetFileSystem(c)
err = func() error {
// TODO: #perf disk I/O in tx
@@ -206,7 +210,13 @@ func handlePartialUploadsFinalizeRequest(c *gin.Context) {
}
// id may have changed if this is an overwrite
r, err := f.ResourceByPathWithRoot(params.Path)
var r core.Resource
if params.Conflict == core.ResourceBindConflictResolutionOverwrite || params.Conflict == core.ResourceBindConflictResolutionDelete {
r, err = f.ResourceByPathWithRoot(params.Path)
} else {
r, err = f.ResourceByID(resourceID)
}
if err != nil {
panic(err)
}

View File

@@ -20,11 +20,11 @@ import (
type ResourceBindConflictResolution int32
const (
ResourceBindConflictResolutionError = ResourceBindConflictResolution(0) // Error if exists
ResourceBindConflictResolutionEnsure = ResourceBindConflictResolution(1) // Error if type mismatch
ResourceBindConflictResolutionRename = ResourceBindConflictResolution(2) // Auto rename new resource
ResourceBindConflictResolutionOverwrite = ResourceBindConflictResolution(3) // Delete existing resource only if type mismatch (preserves props)
ResourceBindConflictResolutionDelete = ResourceBindConflictResolution(4) // Delete existing resource before creating
ResourceBindConflictResolutionError = ResourceBindConflictResolution(0) // Error if exists. ID and path preserved
ResourceBindConflictResolutionEnsure = ResourceBindConflictResolution(1) // Error if type mismatch. ID and path preserved
ResourceBindConflictResolutionRename = ResourceBindConflictResolution(2) // Auto rename new resource. ID preserved, path may change
ResourceBindConflictResolutionOverwrite = ResourceBindConflictResolution(3) // Delete existing resource only if type mismatch (preserves props). Path preserved, ID may change
ResourceBindConflictResolutionDelete = ResourceBindConflictResolution(4) // Delete existing resource before creating. ID and path preserved
)
func CheckResourceNameInvalid(s string) bool {