Skip to content

Commit 45f3da2

Browse files
authored
Merge pull request #1543 from PhilipCramer/feat/appstream-mirror-support
Add appstream support
2 parents 48355f6 + a7a4bb7 commit 45f3da2

72 files changed

Lines changed: 755 additions & 39 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ List of contributors, in chronological order:
8383
* Tim Foerster (https://github.com/tonobo)
8484
* Zhang Xiao (https://github.com/xzhang1)
8585
* Tom Nguyen (https://github.com/lecafard)
86+
* Philip Cramer (https://github.com/PhilipCramer)

api/mirror.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ type mirrorCreateParams struct {
102102
DownloadUdebs bool ` json:"DownloadUdebs"`
103103
// Set "true" to mirror installer files
104104
DownloadInstaller bool ` json:"DownloadInstaller"`
105+
// Set "true" to mirror AppStream (DEP-11) metadata
106+
DownloadAppStream bool ` json:"DownloadAppStream"`
105107
// Set "true" to include dependencies of matching packages when filtering
106108
FilterWithDeps bool ` json:"FilterWithDeps"`
107109
// Set "true" to skip if the given components are in the Release file
@@ -153,7 +155,7 @@ func apiMirrorsCreate(c *gin.Context) {
153155
}
154156

155157
repo, err := deb.NewRemoteRepo(b.Name, b.ArchiveURL, b.Distribution, b.Components, b.Architectures,
156-
b.DownloadSources, b.DownloadUdebs, b.DownloadInstaller)
158+
b.DownloadSources, b.DownloadUdebs, b.DownloadInstaller, b.DownloadAppStream)
157159

158160
if err != nil {
159161
AbortWithJSONError(c, 400, fmt.Errorf("unable to create mirror: %s", err))
@@ -573,6 +575,14 @@ func apiMirrorsUpdate(c *gin.Context) {
573575
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
574576
}
575577

578+
if remote.DownloadAppStream && !remote.IsFlat() {
579+
err = remote.DownloadAppStreamFiles(out, downloader,
580+
context.PackagePool(), collectionFactory.ChecksumCollection(nil), b.IgnoreChecksums)
581+
if err != nil {
582+
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
583+
}
584+
}
585+
576586
if remote.Filter != "" {
577587
var filterQuery deb.PackageQuery
578588

api/mirror_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ func (s *MirrorSuite) TestDeleteMirrorNonExisting(c *C) {
2626
c.Check(response.Body.String(), Equals, "{\"error\":\"unable to drop: mirror with name does-not-exist not found\"}")
2727
}
2828

29+
func (s *MirrorSuite) TestCreateMirrorFlatWithAppStream(c *C) {
30+
body, err := json.Marshal(gin.H{
31+
"Name": "test-flat-appstream",
32+
"ArchiveURL": "http://example.com/repo/",
33+
"Distribution": "./",
34+
"DownloadAppStream": true,
35+
})
36+
c.Assert(err, IsNil)
37+
38+
response, err := s.HTTPRequest("POST", "/api/mirrors", bytes.NewReader(body))
39+
c.Assert(err, IsNil)
40+
c.Check(response.Code, Equals, 400)
41+
c.Check(response.Body.String(), Matches, ".*AppStream.*flat.*")
42+
}
43+
2944
func (s *MirrorSuite) TestCreateMirror(c *C) {
3045
c.ExpectFailure("Need to mock downloads")
3146
body, err := json.Marshal(gin.H{

cmd/db_cleanup.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error {
2626

2727
// collect information about references packages...
2828
existingPackageRefs := deb.NewPackageRefList()
29+
referencedAppStreamFiles := []string{}
2930

3031
// used only in verbose mode to report package use source
3132
packageRefSources := map[string][]string{}
@@ -55,6 +56,10 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error {
5556
}
5657
}
5758

59+
for _, poolPath := range repo.AppStreamFiles {
60+
referencedAppStreamFiles = append(referencedAppStreamFiles, poolPath)
61+
}
62+
5863
return nil
5964
})
6065
if err != nil {
@@ -118,6 +123,11 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error {
118123
return nil
119124
})
120125
}
126+
127+
for _, poolPath := range snapshot.AppStreamFiles {
128+
referencedAppStreamFiles = append(referencedAppStreamFiles, poolPath)
129+
}
130+
121131
return nil
122132
})
123133
if err != nil {
@@ -236,6 +246,7 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error {
236246
return err
237247
}
238248

249+
referencedFiles = append(referencedFiles, referencedAppStreamFiles...)
239250
sort.Strings(referencedFiles)
240251
context.Progress().ShutdownBar()
241252

cmd/mirror_create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
2020
downloadSources := LookupOption(context.Config().DownloadSourcePackages, context.Flags(), "with-sources")
2121
downloadUdebs := context.Flags().Lookup("with-udebs").Value.Get().(bool)
2222
downloadInstaller := context.Flags().Lookup("with-installer").Value.Get().(bool)
23+
downloadAppStream := context.Flags().Lookup("with-appstream").Value.Get().(bool)
2324
ignoreSignatures := context.Config().GpgDisableVerify
2425
if context.Flags().IsSet("ignore-signatures") {
2526
ignoreSignatures = context.Flags().Lookup("ignore-signatures").Value.Get().(bool)
@@ -41,7 +42,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
4142
}
4243

4344
repo, err := deb.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.ArchitecturesList(),
44-
downloadSources, downloadUdebs, downloadInstaller)
45+
downloadSources, downloadUdebs, downloadInstaller, downloadAppStream)
4546
if err != nil {
4647
return fmt.Errorf("unable to create mirror: %s", err)
4748
}
@@ -100,6 +101,7 @@ Example:
100101
}
101102

102103
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
104+
cmd.Flag.Bool("with-appstream", false, "download AppStream (DEP-11) metadata")
103105
cmd.Flag.Bool("with-installer", false, "download additional not packaged installer files")
104106
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
105107
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")

cmd/mirror_edit.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error {
3535
repo.Filter = flag.Value.String() // allows file/stdin with @
3636
case "filter-with-deps":
3737
repo.FilterWithDeps = flag.Value.Get().(bool)
38+
case "with-appstream":
39+
repo.DownloadAppStream = flag.Value.Get().(bool)
3840
case "with-installer":
3941
repo.DownloadInstaller = flag.Value.Get().(bool)
4042
case "with-sources":
@@ -53,6 +55,10 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error {
5355
return fmt.Errorf("unable to edit: flat mirrors don't support udebs")
5456
}
5557

58+
if repo.IsFlat() && repo.DownloadAppStream {
59+
return fmt.Errorf("unable to edit: flat mirrors don't support AppStream (DEP-11) metadata")
60+
}
61+
5662
if repo.Filter != "" {
5763
_, err = query.Parse(repo.Filter)
5864
if err != nil {
@@ -107,6 +113,7 @@ Example:
107113
AddStringOrFileFlag(&cmd.Flag, "filter", "", "filter packages in mirror, use '@file' to read filter from file or '@-' for stdin")
108114
cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well")
109115
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
116+
cmd.Flag.Bool("with-appstream", false, "download AppStream (DEP-11) metadata")
110117
cmd.Flag.Bool("with-installer", false, "download additional not packaged installer files")
111118
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
112119
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")

cmd/mirror_show.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func aptlyMirrorShowTxt(_ *commander.Command, args []string) error {
6161
downloadUdebs = Yes
6262
}
6363
fmt.Printf("Download .udebs: %s\n", downloadUdebs)
64+
downloadAppStream := No
65+
if repo.DownloadAppStream {
66+
downloadAppStream = Yes
67+
}
68+
fmt.Printf("Download AppStream: %s\n", downloadAppStream)
6469
if repo.Filter != "" {
6570
fmt.Printf("Filter: %s\n", repo.Filter)
6671
filterWithDeps := No

cmd/mirror_update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
6464
return fmt.Errorf("unable to update: %s", err)
6565
}
6666

67+
if repo.DownloadAppStream && !repo.IsFlat() {
68+
context.Progress().Printf("Downloading AppStream metadata...\n")
69+
err = repo.DownloadAppStreamFiles(context.Progress(), context.Downloader(),
70+
context.PackagePool(), collectionFactory.ChecksumCollection(nil), ignoreChecksums)
71+
if err != nil {
72+
return fmt.Errorf("unable to update: %s", err)
73+
}
74+
}
75+
6776
if repo.Filter != "" {
6877
context.Progress().Printf("Applying filter...\n")
6978
var filterQuery deb.PackageQuery

completion.d/_aptly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ local keyring="*-keyring=[gpg keyring to use when verifying Release file (could
185185
$keyring \
186186
"-with-sources=[download source packages in addition to binary packages]:$bool" \
187187
"-with-udebs=[download .udeb packages (Debian installer support)]:$bool" \
188+
"-with-appstream=[download AppStream (DEP-11) metadata]:$bool" \
188189
"(-)2:new mirror name: " ":archive url:_urls" ":distribution:($dists)" "*:components:_values -s ' ' components $components"
189190
;;
190191
list)
@@ -224,6 +225,7 @@ local keyring="*-keyring=[gpg keyring to use when verifying Release file (could
224225
"-filter-with-deps=[when filtering, include dependencies of matching packages as well]:$bool" \
225226
"-with-sources=[download source packages in addition to binary packages]:$bool" \
226227
"-with-udebs=[download .udeb packages (Debian installer support)]:$bool" \
228+
"-with-appstream=[download AppStream (DEP-11) metadata]:$bool" \
227229
"(-)2:mirror name:$mirrors"
228230
;;
229231
search)

completion.d/aptly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ _aptly()
203203
"create")
204204
if [[ $numargs -eq 0 ]]; then
205205
if [[ "$cur" == -* ]]; then
206-
COMPREPLY=($(compgen -W "-filter= -filter-with-deps -force-components -ignore-signatures -keyring= -with-installer -with-sources -with-udebs" -- ${cur}))
206+
COMPREPLY=($(compgen -W "-filter= -filter-with-deps -force-components -ignore-signatures -keyring= -with-appstream -with-installer -with-sources -with-udebs" -- ${cur}))
207207
return 0
208208
fi
209209
fi
210210
;;
211211
"edit")
212212
if [[ $numargs -eq 0 ]]; then
213213
if [[ "$cur" == -* ]]; then
214-
COMPREPLY=($(compgen -W "-archive-url= -filter= -filter-with-deps -ignore-signatures -keyring= -with-installer -with-sources -with-udebs" -- ${cur}))
214+
COMPREPLY=($(compgen -W "-archive-url= -filter= -filter-with-deps -ignore-signatures -keyring= -with-appstream -with-installer -with-sources -with-udebs" -- ${cur}))
215215
else
216216
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
217217
fi

0 commit comments

Comments
 (0)