Skip to content

Commit 8612601

Browse files
committed
publish: persist multidist flag
1 parent 3e7bec5 commit 8612601

15 files changed

Lines changed: 310 additions & 55 deletions

api/publish.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
130130
var resources []string
131131
collectionFactory := context.NewCollectionFactory()
132132

133-
if b.SourceKind == "snapshot" {
133+
if b.SourceKind == deb.SourceSnapshot {
134134
var snapshot *deb.Snapshot
135135

136136
snapshotCollection := collectionFactory.SnapshotCollection()
@@ -182,7 +182,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
182182
return
183183
}
184184

185-
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory)
185+
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory, b.MultiDist)
186186
if err != nil {
187187
AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err))
188188
return
@@ -232,7 +232,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
232232
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
233233
}
234234

235-
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite, b.MultiDist)
235+
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite)
236236
if err != nil {
237237
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to publish: %s", err)
238238
}
@@ -263,7 +263,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
263263
Name string `binding:"required"`
264264
}
265265
AcquireByHash *bool
266-
MultiDist bool
266+
MultiDist *bool
267267
}
268268

269269
if c.Bind(&b) != nil {
@@ -339,10 +339,14 @@ func apiPublishUpdateSwitch(c *gin.Context) {
339339
published.AcquireByHash = *b.AcquireByHash
340340
}
341341

342+
if b.MultiDist != nil {
343+
published.MultiDist = *b.MultiDist
344+
}
345+
342346
resources = append(resources, string(published.Key()))
343347
taskName := fmt.Sprintf("Update published %s (%s): %s", published.SourceKind, strings.Join(updatedComponents, " "), strings.Join(updatedSnapshots, ", "))
344348
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
345-
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite, b.MultiDist)
349+
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite)
346350
if err != nil {
347351
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
348352
}

cmd/publish_snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
118118
butAutomaticUpgrades := context.Flags().Lookup("butautomaticupgrades").Value.String()
119119
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)
120120

121-
published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory)
121+
published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory, multiDist)
122122
if err != nil {
123123
return fmt.Errorf("unable to publish: %s", err)
124124
}
@@ -166,7 +166,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
166166
context.Progress().ColoredPrintf("@rWARNING@|: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool.\n")
167167
}
168168

169-
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
169+
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
170170
if err != nil {
171171
return fmt.Errorf("unable to publish: %s", err)
172172
}

cmd/publish_switch.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
1313
var err error
1414

1515
components := strings.Split(context.Flags().Lookup("component").Value.String(), ",")
16-
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)
1716

1817
if len(args) < len(components)+1 || len(args) > len(components)+2 {
1918
cmd.Usage()
@@ -96,7 +95,11 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
9695
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
9796
}
9897

99-
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
98+
if context.Flags().IsSet("multi-dist") {
99+
published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool)
100+
}
101+
102+
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
100103
if err != nil {
101104
return fmt.Errorf("unable to publish: %s", err)
102105
}

cmd/publish_update.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
1717

1818
distribution := args[0]
1919
param := "."
20-
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)
2120

2221
if len(args) == 2 {
2322
param = args[1]
@@ -65,7 +64,11 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
6564
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
6665
}
6766

68-
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
67+
if context.Flags().IsSet("multi-dist") {
68+
published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool)
69+
}
70+
71+
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
6972
if err != nil {
7073
return fmt.Errorf("unable to publish: %s", err)
7174
}

deb/publish.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ type PublishedRepo struct {
7070

7171
// Provide index files per hash also
7272
AcquireByHash bool
73+
74+
// Support multiple distributions
75+
MultiDist bool
7376
}
7477

7578
// ParsePrefix splits [storage:]prefix into components
@@ -153,13 +156,14 @@ func walkUpTree(source interface{}, collectionFactory *CollectionFactory) (rootD
153156
// distribution and architectures are user-defined properties
154157
// components & sources are lists of component to source mapping (*Snapshot or *LocalRepo)
155158
func NewPublishedRepo(storage, prefix, distribution string, architectures []string,
156-
components []string, sources []interface{}, collectionFactory *CollectionFactory) (*PublishedRepo, error) {
159+
components []string, sources []interface{}, collectionFactory *CollectionFactory, multiDist bool) (*PublishedRepo, error) {
157160
result := &PublishedRepo{
158161
UUID: uuid.New(),
159162
Storage: storage,
160163
Architectures: architectures,
161164
Sources: make(map[string]string),
162165
sourceItems: make(map[string]repoSourceItem),
166+
MultiDist: multiDist,
163167
}
164168

165169
if len(sources) == 0 {
@@ -315,6 +319,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
315319
"Storage": p.Storage,
316320
"SkipContents": p.SkipContents,
317321
"AcquireByHash": p.AcquireByHash,
322+
"MultiDist": p.MultiDist,
318323
})
319324
}
320325

@@ -547,7 +552,7 @@ func (p *PublishedRepo) GetCodename() string {
547552

548553
// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them
549554
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageProvider aptly.PublishedStorageProvider,
550-
collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite, multiDist bool) error {
555+
collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite bool) error {
551556
publishedStorage := publishedStorageProvider.GetPublishedStorage(p.Storage)
552557

553558
err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool"))
@@ -659,7 +664,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
659664
if err2 != nil {
660665
return err2
661666
}
662-
if multiDist {
667+
if p.MultiDist {
663668
relPath = filepath.Join("pool", p.Distribution, component, poolDir)
664669
} else {
665670
relPath = filepath.Join("pool", component, poolDir)

deb/publish_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func BenchmarkListReferencedFiles(b *testing.B) {
9494
repo.UpdateRefList(refs.Merge(sharedRefs, false, true))
9595
repoCollection.Add(repo)
9696

97-
publish, err := NewPublishedRepo("", "test", "", nil, []string{defaultComponent}, []interface{}{repo}, factory)
97+
publish, err := NewPublishedRepo("", "test", "", nil, []string{defaultComponent}, []interface{}{repo}, factory, false)
9898
if err != nil {
9999
b.Fatal(err)
100100
}

0 commit comments

Comments
 (0)