Skip to content

Commit fb47d41

Browse files
Merge pull request #51 from NamelessOne91/multi_arch_repo_support
Filter packages in multi-architecture repositories
2 parents 9b2c4d4 + 596281e commit fb47d41

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

cmd/sync.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
123123
return nil, err
124124
}
125125

126+
archs := map[string]bool{}
127+
for _, archString := range httpRepo.Archs {
128+
archs[archString] = true
129+
}
130+
126131
var storage get.Storage
127132
switch config.Storage.Type {
128133
case "file":
@@ -133,7 +138,7 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
133138
return nil, err
134139
}
135140
}
136-
syncers = append(syncers, get.NewSyncer(*repoURL, storage))
141+
syncers = append(syncers, get.NewSyncer(*repoURL, archs, storage))
137142
}
138143

139144
return syncers, nil

get/syncer.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ var (
108108
type Syncer struct {
109109
// URL of the repo this syncer syncs
110110
URL url.URL
111+
archs map[string]bool
111112
storage Storage
112113
}
113114

@@ -124,8 +125,8 @@ const (
124125
)
125126

126127
// NewSyncer creates a new Syncer
127-
func NewSyncer(url url.URL, storage Storage) *Syncer {
128-
return &Syncer{url, storage}
128+
func NewSyncer(url url.URL, archs map[string]bool, storage Storage) *Syncer {
129+
return &Syncer{url, archs, storage}
129130
}
130131

131132
// StoreRepo stores an HTTP repo in a Storage, automatically retrying in case of recoverable errors
@@ -418,18 +419,23 @@ func (r *Syncer) processPrimary(path string, checksumMap map[string]XMLChecksum,
418419
return
419420
}
420421

422+
allArchs := len(r.archs) == 0
421423
for _, pack := range primary.Packages {
422-
if SkipLegacy && (pack.Arch == "i586" || pack.Arch == "i686") {
424+
legacyPackage := (pack.Arch == "i586" || pack.Arch == "i686")
425+
426+
if SkipLegacy && legacyPackage {
423427
fmt.Println("Skipping legacy package:", pack.Location.Href)
424428
continue
425429
}
426430

427-
decision := r.decide(pack.Location.Href, pack.Checksum, checksumMap)
428-
switch decision {
429-
case Download:
430-
packagesToDownload = append(packagesToDownload, pack)
431-
case Recycle:
432-
packagesToRecycle = append(packagesToRecycle, pack)
431+
if allArchs || pack.Arch == repoType.Noarch || r.archs[pack.Arch] || (r.archs["x86_64"] && legacyPackage) {
432+
decision := r.decide(pack.Location.Href, pack.Checksum, checksumMap)
433+
switch decision {
434+
case Download:
435+
packagesToDownload = append(packagesToDownload, pack)
436+
case Recycle:
437+
packagesToRecycle = append(packagesToRecycle, pack)
438+
}
433439
}
434440
}
435441
return

get/syncer_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ func TestStoreRepo(t *testing.T) {
1818
t.Error(err)
1919
}
2020

21+
archs := map[string]bool{
22+
"x86_64": true,
23+
}
2124
storage := NewFileStorage(directory)
2225
url, err := url.Parse("http://localhost:8080/repo")
2326
if err != nil {
2427
t.Error(err)
2528
}
26-
syncer := NewSyncer(*url, storage)
29+
syncer := NewSyncer(*url, archs, storage)
2730

2831
// first sync
2932
err = syncer.StoreRepo()
@@ -72,12 +75,15 @@ func TestStoreRepoZstd(t *testing.T) {
7275
t.Error(err)
7376
}
7477

78+
archs := map[string]bool{
79+
"x86_64": true,
80+
}
7581
storage := NewFileStorage(directory)
7682
url, err := url.Parse("http://localhost:8080/zstrepo")
7783
if err != nil {
7884
t.Error(err)
7985
}
80-
syncer := NewSyncer(*url, storage)
86+
syncer := NewSyncer(*url, archs, storage)
8187

8288
// first sync
8389
err = syncer.StoreRepo()
@@ -125,12 +131,16 @@ func TestStoreDebRepo(t *testing.T) {
125131
t.Error(err)
126132
}
127133

134+
archs := map[string]bool{
135+
"amd64": true,
136+
}
137+
128138
storage := NewFileStorage(directory)
129139
url, err := url.Parse("http://localhost:8080/deb_repo")
130140
if err != nil {
131141
t.Error(err)
132142
}
133-
syncer := NewSyncer(*url, storage)
143+
syncer := NewSyncer(*url, archs, storage)
134144

135145
// first sync
136146
err = syncer.StoreRepo()

0 commit comments

Comments
 (0)