From f8efb3e9b7ce95024bc8ca97d3bdfb14841066b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roth?= Date: Mon, 4 May 2026 16:12:54 +0200 Subject: [PATCH] publish update: lock all snapshots and repos as well --- api/publish.go | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/api/publish.go b/api/publish.go index 3c796b45..649486f1 100644 --- a/api/publish.go +++ b/api/publish.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strings" + "errors" "github.com/aptly-dev/aptly/aptly" "github.com/aptly-dev/aptly/deb" @@ -465,18 +466,54 @@ func apiPublishUpdateSwitch(c *gin.Context) { return } + resources := []string{string(published.Key())} + if published.SourceKind == deb.SourceLocalRepo { if len(b.Snapshots) > 0 { AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("snapshots shouldn't be given when updating local repo")) return } + + // FIXME: lock repo ? + // localCollection := collectionFactory.LocalRepoCollection() + // for _, source := range b.Sources { + // components = append(components, source.Component) + // names = append(names, source.Name) + + // localRepo, err = localCollection.ByName(source.Name) + // if err != nil { + // AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to publish: %s", err)) + // return + // } + + // resources = append(resources, string(localRepo.Key())) + // } } else if published.SourceKind == deb.SourceSnapshot { for _, snapshotInfo := range b.Snapshots { - _, err2 := snapshotCollection.ByName(snapshotInfo.Name) + snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name) if err2 != nil { AbortWithJSONError(c, http.StatusNotFound, err2) return } + resources = append(resources, string(snapshot.ResourceKey())) + // for repo := snapshot.LocalRepos { + // } + + fmt.Printf("RACE DEBUG: source ids: %s\n", snapshot.SourceIDs) + for _, sourceID := range snapshot.SourceIDs { + if snapshot.SourceKind == deb.SourceSnapshot { + // FIXME: implement + err := errors.New("not implemented") + AbortWithJSONError(c, http.StatusNotFound, err) + } else if snapshot.SourceKind == deb.SourceLocalRepo { + var repo *deb.LocalRepo + repo, err = context.NewCollectionFactory().LocalRepoCollection().ByUUID(sourceID) + if err != nil { + AbortWithJSONError(c, http.StatusNotFound, err2) + } + resources = append(resources, string(repo.Key())) + } + } } } else { AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unknown published repository type")) @@ -515,9 +552,6 @@ func apiPublishUpdateSwitch(c *gin.Context) { published.Version = *b.Version } - - fmt.Printf("apiPublishUpdateSwitch: %s\n", string(published.Key())) - resources := []string{string(published.Key())} taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { err = collection.LoadComplete(published, collectionFactory)