From a29034caa5175926ed83a8c6eaa3077aaf948834 Mon Sep 17 00:00:00 2001 From: Michael Koval Date: Tue, 20 Jan 2015 03:21:21 -0500 Subject: [PATCH 1/3] Implemented apiPublishUpdateSwitch. --- api/publish.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/api/publish.go b/api/publish.go index e6318eaf..fd972b9f 100644 --- a/api/publish.go +++ b/api/publish.go @@ -168,7 +168,67 @@ func apiPublishRepoOrSnapshot(c *gin.Context) { // PUT /publish/:prefix/:distribution func apiPublishUpdateSwitch(c *gin.Context) { - c.JSON(400, gin.H{}) + param := parseEscapedPath(c.Params.ByName("prefix")) + storage, prefix := deb.ParsePrefix(param) + distribution := c.Params.ByName("distribution") + + var b struct { + ForceOverwrite bool + Signing SigningOptions + } + + if !c.Bind(&b) { + return + } + + signer, err := getSigner(&b.Signing) + if err != nil { + c.Fail(500, fmt.Errorf("unable to initialize GPG signer: %s", err)) + return + } + + collection := context.CollectionFactory().PublishedRepoCollection() + collection.Lock() + defer collection.Unlock() + + published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution) + if err != nil { + c.Fail(500, fmt.Errorf("unable to update: %s", err)) + return + } + if published.SourceKind != "local" { + c.Fail(500, fmt.Errorf("unable to update: not a local repository")) + return + } + + err = collection.LoadComplete(published, context.CollectionFactory()) + if err != nil { + c.Fail(500, fmt.Errorf("unable to update: %s", err)) + return + } + + components := published.Components() + for _, component := range components { + published.UpdateLocalRepo(component) + } + + err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, context.Progress(), b.ForceOverwrite) + if err != nil { + c.Fail(500, fmt.Errorf("unable to update: %s", err)) + } + + err = collection.Update(published) + if err != nil { + c.Fail(500, fmt.Errorf("unable to save to DB: %s", err)) + } + + err = collection.CleanupPrefixComponentFiles(published.Prefix, components, + context.GetPublishedStorage(storage), context.CollectionFactory(), context.Progress()) + if err != nil { + c.Fail(500, fmt.Errorf("unable to update: %s", err)) + } + + c.JSON(200, published) } // DELETE /publish/:prefix/:distribution From 4963d0a1d7a8aecc2beb6fcefed44ea891e0b5da Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 7 Feb 2015 18:53:25 +0300 Subject: [PATCH 2/3] Add @mkoval to list of AUTHORS. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 9ae1173f..e3bd5a02 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ List of contributors, in chronological order: * Chris Read (https://github.com/cread) * Sylvain Baubeau (https://github.com/lebauce) * Andrea Bernardo Ciddio (https://github.com/bcandrea) +* Michael Koval (https://github.com/mkoval) From 24418ab0a4409ae68003837623bcef541eda7846 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 7 Feb 2015 19:01:06 +0300 Subject: [PATCH 3/3] Small fixes to publish update API. #174 --- api/publish.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/publish.go b/api/publish.go index 07344d3d..5abb6721 100644 --- a/api/publish.go +++ b/api/publish.go @@ -188,17 +188,22 @@ func apiPublishUpdateSwitch(c *gin.Context) { return } + // published.LoadComplete would touch local repo collection + localRepoCollection := context.CollectionFactory().LocalRepoCollection() + localRepoCollection.RLock() + defer localRepoCollection.RUnlock() + collection := context.CollectionFactory().PublishedRepoCollection() collection.Lock() defer collection.Unlock() published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution) if err != nil { - c.Fail(500, fmt.Errorf("unable to update: %s", err)) + c.Fail(404, fmt.Errorf("unable to update: %s", err)) return } if published.SourceKind != "local" { - c.Fail(500, fmt.Errorf("unable to update: not a local repository")) + c.Fail(400, fmt.Errorf("unable to update: not a local repository")) return }