mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-31 04:30:44 +00:00
fix(snapshot): check duplicate name even when renaming to same name
The SnapshotsAPITestCreateUpdate test expects that PUT /api/snapshots/:name with the same Name in the body returns a conflict error. The previous fix added 'b.Name != name' guards to skip the duplicate check when the name hasn't changed, but this broke the test which expects the old behavior: any existing name (including the snapshot's own current name) should be rejected as a duplicate. Remove the 'b.Name != name' condition from both the pre-task validation and the in-task duplicate check so the behavior matches the original.
This commit is contained in:
+3
-3
@@ -340,7 +340,7 @@ func apiSnapshotsUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pre-task validation of new name if provided
|
// Pre-task validation of new name if provided
|
||||||
if b.Name != "" && b.Name != name {
|
if b.Name != "" {
|
||||||
_, err = collection.ByName(b.Name)
|
_, err = collection.ByName(b.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name))
|
AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name))
|
||||||
@@ -362,8 +362,8 @@ func apiSnapshotsUpdate(c *gin.Context) {
|
|||||||
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fresh duplicate check inside lock (if renaming)
|
// Fresh duplicate check inside lock
|
||||||
if b.Name != "" && b.Name != name {
|
if b.Name != "" {
|
||||||
_, err := taskCollection.ByName(b.Name)
|
_, err := taskCollection.ByName(b.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name)
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name)
|
||||||
|
|||||||
Reference in New Issue
Block a user