Skip to content

Commit

Permalink
Merge pull request #51 from NamelessOne91/multi_arch_repo_support
Browse files Browse the repository at this point in the history
Filter packages in multi-architecture repositories
  • Loading branch information
NamelessOne91 authored Oct 16, 2024
2 parents 9b2c4d4 + 596281e commit fb47d41
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
7 changes: 6 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
return nil, err
}

archs := map[string]bool{}
for _, archString := range httpRepo.Archs {
archs[archString] = true
}

var storage get.Storage
switch config.Storage.Type {
case "file":
Expand All @@ -133,7 +138,7 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
return nil, err
}
}
syncers = append(syncers, get.NewSyncer(*repoURL, storage))
syncers = append(syncers, get.NewSyncer(*repoURL, archs, storage))
}

return syncers, nil
Expand Down
24 changes: 15 additions & 9 deletions get/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var (
type Syncer struct {
// URL of the repo this syncer syncs
URL url.URL
archs map[string]bool
storage Storage
}

Expand All @@ -124,8 +125,8 @@ const (
)

// NewSyncer creates a new Syncer
func NewSyncer(url url.URL, storage Storage) *Syncer {
return &Syncer{url, storage}
func NewSyncer(url url.URL, archs map[string]bool, storage Storage) *Syncer {
return &Syncer{url, archs, storage}
}

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

allArchs := len(r.archs) == 0
for _, pack := range primary.Packages {
if SkipLegacy && (pack.Arch == "i586" || pack.Arch == "i686") {
legacyPackage := (pack.Arch == "i586" || pack.Arch == "i686")

if SkipLegacy && legacyPackage {
fmt.Println("Skipping legacy package:", pack.Location.Href)
continue
}

decision := r.decide(pack.Location.Href, pack.Checksum, checksumMap)
switch decision {
case Download:
packagesToDownload = append(packagesToDownload, pack)
case Recycle:
packagesToRecycle = append(packagesToRecycle, pack)
if allArchs || pack.Arch == repoType.Noarch || r.archs[pack.Arch] || (r.archs["x86_64"] && legacyPackage) {
decision := r.decide(pack.Location.Href, pack.Checksum, checksumMap)
switch decision {
case Download:
packagesToDownload = append(packagesToDownload, pack)
case Recycle:
packagesToRecycle = append(packagesToRecycle, pack)
}
}
}
return
Expand Down
16 changes: 13 additions & 3 deletions get/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ func TestStoreRepo(t *testing.T) {
t.Error(err)
}

archs := map[string]bool{
"x86_64": true,
}
storage := NewFileStorage(directory)
url, err := url.Parse("http://localhost:8080/repo")
if err != nil {
t.Error(err)
}
syncer := NewSyncer(*url, storage)
syncer := NewSyncer(*url, archs, storage)

// first sync
err = syncer.StoreRepo()
Expand Down Expand Up @@ -72,12 +75,15 @@ func TestStoreRepoZstd(t *testing.T) {
t.Error(err)
}

archs := map[string]bool{
"x86_64": true,
}
storage := NewFileStorage(directory)
url, err := url.Parse("http://localhost:8080/zstrepo")
if err != nil {
t.Error(err)
}
syncer := NewSyncer(*url, storage)
syncer := NewSyncer(*url, archs, storage)

// first sync
err = syncer.StoreRepo()
Expand Down Expand Up @@ -125,12 +131,16 @@ func TestStoreDebRepo(t *testing.T) {
t.Error(err)
}

archs := map[string]bool{
"amd64": true,
}

storage := NewFileStorage(directory)
url, err := url.Parse("http://localhost:8080/deb_repo")
if err != nil {
t.Error(err)
}
syncer := NewSyncer(*url, storage)
syncer := NewSyncer(*url, archs, storage)

// first sync
err = syncer.StoreRepo()
Expand Down

0 comments on commit fb47d41

Please sign in to comment.