Skip to content

Commit 9b2c4d4

Browse files
Merge pull request #50 from NamelessOne91/legacy_pkgs_handling
Sync all repo packages by default, use a flag to skip legacy ones
2 parents b6140b0 + f83b9f2 commit 9b2c4d4

File tree

3 files changed

+36
-52
lines changed

3 files changed

+36
-52
lines changed

cmd/sync.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var (
7777
}
7878
thisRepo string
7979
archs string
80-
syncLegacyPackages bool
80+
skipLegacyPackages bool
8181
)
8282

8383
// Config maps the configuration in minima.yaml
@@ -93,8 +93,8 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
9393
if err != nil {
9494
return nil, err
9595
}
96-
//---passing the flag value to a global variable in get package, to trigger syncing of i586 rpms inside x86_64
97-
get.Legacy = syncLegacyPackages
96+
//---passing the flag value to a global variable in get package, to disables syncing of i586 and i686 rpms (usually inside x86_64)
97+
get.SkipLegacy = skipLegacyPackages
9898

9999
if config.SCC.Username != "" {
100100
if thisRepo != "" {
@@ -123,11 +123,6 @@ 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-
131126
var storage get.Storage
132127
switch config.Storage.Type {
133128
case "file":
@@ -138,7 +133,7 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
138133
return nil, err
139134
}
140135
}
141-
syncers = append(syncers, get.NewSyncer(*repoURL, archs, storage))
136+
syncers = append(syncers, get.NewSyncer(*repoURL, storage))
142137
}
143138

144139
return syncers, nil
@@ -162,5 +157,5 @@ func init() {
162157
// local flags
163158
syncCmd.Flags().StringVarP(&thisRepo, "repository", "r", "", "flag that can specifies a single repo (example: SLES11-SP4-Updates)")
164159
syncCmd.Flags().StringVarP(&archs, "arch", "a", "", "flag that specifies covered archs in the given repo")
165-
syncCmd.Flags().BoolVarP(&syncLegacyPackages, "legacypackages", "l", false, "flag that triggers mirroring of i586 pkgs in x86_64 repos")
160+
syncCmd.Flags().BoolVarP(&skipLegacyPackages, "nolegacy", "l", false, "flag that disables mirroring of i586 and i686 pkgs")
166161
}

get/syncer.go

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,31 @@ var (
101101
Noarch: "all",
102102
},
103103
}
104-
Legacy bool
104+
SkipLegacy bool
105105
)
106106

107107
// Syncer syncs repos from an HTTP source to a Storage
108108
type Syncer struct {
109109
// URL of the repo this syncer syncs
110110
URL url.URL
111-
archs map[string]bool
112111
storage Storage
113112
}
114113

114+
// Decision encodes what to do with a file
115+
type Decision int
116+
117+
const (
118+
// Download means the Syncer will download a file
119+
Download Decision = iota
120+
// Recycle means the Syncer will copy an existing file without downloading
121+
Recycle
122+
// Skip means the Syncer detected an already-existing file and has nothing to do
123+
Skip
124+
)
125+
115126
// NewSyncer creates a new Syncer
116-
func NewSyncer(url url.URL, archs map[string]bool, storage Storage) *Syncer {
117-
return &Syncer{url, archs, storage}
127+
func NewSyncer(url url.URL, storage Storage) *Syncer {
128+
return &Syncer{url, storage}
118129
}
119130

120131
// StoreRepo stores an HTTP repo in a Storage, automatically retrying in case of recoverable errors
@@ -190,11 +201,6 @@ func (r *Syncer) storeRepo(checksumMap map[string]XMLChecksum) (err error) {
190201
return
191202
}
192203

193-
// downloadStore downloads a repo-relative path into a file
194-
func (r *Syncer) downloadStore(path string, description string) error {
195-
return r.downloadStoreApply(path, "", description, 0, util.Nop)
196-
}
197-
198204
// downloadStoreApply downloads a repo-relative path into a file, while applying a ReaderConsumer
199205
func (r *Syncer) downloadStoreApply(relativePath string, checksum string, description string, hash crypto.Hash, f util.ReaderConsumer) error {
200206
log.Printf("Downloading %v...", description)
@@ -232,6 +238,7 @@ func (r *Syncer) processMetadata(checksumMap map[string]XMLChecksum) (packagesTo
232238
log.Printf(data[i].Location.Href)
233239
metadataLocation := data[i].Location.Href
234240
metadataChecksum := data[i].Checksum
241+
235242
decision := r.decide(metadataLocation, metadataChecksum, checksumMap)
236243
switch decision {
237244
case Download:
@@ -404,39 +411,30 @@ func (r *Syncer) processPrimary(path string, checksumMap map[string]XMLChecksum,
404411
if err != nil {
405412
return
406413
}
414+
407415
compType := strings.Trim(filepath.Ext(path), ".")
408416
primary, err := repoType.DecodePackages(reader, compType)
409417
if err != nil {
410418
return
411419
}
412420

413-
allArchs := len(r.archs) == 0
414421
for _, pack := range primary.Packages {
415-
if allArchs || pack.Arch == repoType.Noarch || r.archs[pack.Arch] || (r.archs["i586"] && pack.Arch == "i686") || (Legacy && (r.archs["x86_64"] && (pack.Arch == "i586" || pack.Arch == "i686"))) {
416-
decision := r.decide(pack.Location.Href, pack.Checksum, checksumMap)
417-
switch decision {
418-
case Download:
419-
packagesToDownload = append(packagesToDownload, pack)
420-
case Recycle:
421-
packagesToRecycle = append(packagesToRecycle, pack)
422-
}
422+
if SkipLegacy && (pack.Arch == "i586" || pack.Arch == "i686") {
423+
fmt.Println("Skipping legacy package:", pack.Location.Href)
424+
continue
425+
}
426+
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)
423433
}
424434
}
425435
return
426436
}
427437

428-
// Decision encodes what to do with a file
429-
type Decision int
430-
431-
const (
432-
// Download means the Syncer will download a file
433-
Download Decision = iota
434-
// Recycle means the Syncer will copy an existing file without downloading
435-
Recycle
436-
// Skip means the Syncer detected an already-existing file and has nothing to do
437-
Skip
438-
)
439-
440438
func (r *Syncer) decide(location string, checksum XMLChecksum, checksumMap map[string]XMLChecksum) Decision {
441439
previousChecksum, foundInChecksumMap := checksumMap[location]
442440

get/syncer_test.go

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

21-
archs := map[string]bool{
22-
"x86_64": true,
23-
}
2421
storage := NewFileStorage(directory)
2522
url, err := url.Parse("http://localhost:8080/repo")
2623
if err != nil {
2724
t.Error(err)
2825
}
29-
syncer := NewSyncer(*url, archs, storage)
26+
syncer := NewSyncer(*url, storage)
3027

3128
// first sync
3229
err = syncer.StoreRepo()
@@ -75,15 +72,12 @@ func TestStoreRepoZstd(t *testing.T) {
7572
t.Error(err)
7673
}
7774

78-
archs := map[string]bool{
79-
"x86_64": true,
80-
}
8175
storage := NewFileStorage(directory)
8276
url, err := url.Parse("http://localhost:8080/zstrepo")
8377
if err != nil {
8478
t.Error(err)
8579
}
86-
syncer := NewSyncer(*url, archs, storage)
80+
syncer := NewSyncer(*url, storage)
8781

8882
// first sync
8983
err = syncer.StoreRepo()
@@ -131,15 +125,12 @@ func TestStoreDebRepo(t *testing.T) {
131125
t.Error(err)
132126
}
133127

134-
archs := map[string]bool{
135-
"amd64": true,
136-
}
137128
storage := NewFileStorage(directory)
138129
url, err := url.Parse("http://localhost:8080/deb_repo")
139130
if err != nil {
140131
t.Error(err)
141132
}
142-
syncer := NewSyncer(*url, archs, storage)
133+
syncer := NewSyncer(*url, storage)
143134

144135
// first sync
145136
err = syncer.StoreRepo()

0 commit comments

Comments
 (0)