Skip to content

Commit

Permalink
Fixing tests and fix cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Fiehe <[email protected]>
  • Loading branch information
Christoph Fiehe committed Oct 12, 2024
1 parent 5dd225f commit cd49bf6
Show file tree
Hide file tree
Showing 63 changed files with 190 additions and 112 deletions.
10 changes: 6 additions & 4 deletions api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ func apiPublishUpdateSwitch(c *gin.Context) {
}

if b.SkipCleanup == nil || !*b.SkipCleanup {
err = collection.CleanupPrefixComponentFiles(context, published, result.AddedComponents(), result.UpdatedComponents(), result.RemovedComponents(),
collectionFactory, out)
cleanComponents := make([]string, 0, len(result.UpdatedSources)+len(result.RemovedSources))
cleanComponents = append(append(cleanComponents, result.UpdatedComponents()...), result.RemovedComponents()...)
err = collection.CleanupPrefixComponentFiles(context, published, cleanComponents, collectionFactory, out)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
}
Expand Down Expand Up @@ -846,8 +847,9 @@ func apiPublishUpdate(c *gin.Context) {
}

if b.SkipCleanup == nil || !*b.SkipCleanup {
err = collection.CleanupPrefixComponentFiles(context, published,
result.AddedComponents(), result.UpdatedComponents(), result.RemovedComponents(), collectionFactory, out)
cleanComponents := make([]string, 0, len(result.UpdatedSources)+len(result.RemovedSources))
cleanComponents = append(append(cleanComponents, result.UpdatedComponents()...), result.RemovedComponents()...)
err = collection.CleanupPrefixComponentFiles(context, published, cleanComponents, collectionFactory, out)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mirror_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to update: %s", err)
}

context.Progress().Printf("\nMirror `%s` has been successfully updated.\n", repo.Name)
context.Progress().Printf("\nMirror `%s` has been updated successfully.\n", repo.Name)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/publish_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func aptlyPublishDrop(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to remove: %s", err)
}

context.Progress().Printf("\nPublished repository has been removed successfully.\n")
context.Progress().Printf("\nPublished %s repository %s has been removed successfully.\n", published.SourceKind, published.String())

Check failure on line 35 in cmd/publish_drop.go

View workflow job for this annotation

GitHub Actions / Test (Ubuntu 22.04)

undefined: published

return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/publish_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {

skipCleanup := context.Flags().Lookup("skip-cleanup").Value.Get().(bool)
if !skipCleanup {
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(context, published,
[]string{}, components, []string{}, collectionFactory, context.Progress())
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(context, published, components, collectionFactory, context.Progress())
if err != nil {
return fmt.Errorf("unable to switch: %s", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/publish_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {

skipCleanup := context.Flags().Lookup("skip-cleanup").Value.Get().(bool)
if !skipCleanup {
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(context, published,
result.AddedComponents(), result.UpdatedComponents(), result.RemovedComponents(), collectionFactory, context.Progress())
cleanComponents := make([]string, 0, len(result.UpdatedSources)+len(result.RemovedSources))
cleanComponents = append(append(cleanComponents, result.UpdatedComponents()...), result.RemovedComponents()...)
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(context, published, cleanComponents, collectionFactory, context.Progress())
if err != nil {
return fmt.Errorf("unable to update: %s", err)
}
}

context.Progress().Printf("\nPublished %s repository %s has been successfully updated.\n", published.SourceKind, published.String())
context.Progress().Printf("\nPublished %s repository %s has been updated successfully.\n", published.SourceKind, published.String())

return err
}
Expand Down
107 changes: 80 additions & 27 deletions deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -1462,73 +1462,127 @@ func (collection *PublishedRepoCollection) listReferencedFilesByComponent(prefix

// CleanupPrefixComponentFiles removes all unreferenced files in published storage under prefix/component pair
func (collection *PublishedRepoCollection) CleanupPrefixComponentFiles(publishedStorageProvider aptly.PublishedStorageProvider,
published *PublishedRepo, addedComponents, updatedComponents, removedComponents []string,
collectionFactory *CollectionFactory, progress aptly.Progress) error {
published *PublishedRepo, cleanComponents []string, collectionFactory *CollectionFactory, progress aptly.Progress) error {

var err error

collection.loadList()

storage := published.Storage
prefix := published.Prefix
distribution := published.Distribution
multiDist := published.MultiDist

rootPath := filepath.Join(prefix, "dists", distribution)
publishedStorage := publishedStorageProvider.GetPublishedStorage(published.Storage)

components := make([]string, 0, len(addedComponents)+len(updatedComponents)+len(removedComponents))
components = append(append(append(components, addedComponents...), updatedComponents...), removedComponents...)
sort.Strings(components)
sort.Strings(cleanComponents)
publishedComponents := published.Components()
removedComponents := utils.StrSlicesSubstract(cleanComponents, publishedComponents)
updatedComponents := utils.StrSlicesSubstract(cleanComponents, removedComponents)

if progress != nil {
progress.Printf("Cleaning up published repository %s/%s...\n", published.StoragePrefix(), distribution)
}

for _, component := range removedComponents {
if progress != nil {
progress.Printf("Removing component %q from prefix %q...\n", component, prefix)
progress.Printf("Removing component %q...\n", component)
}

err := publishedStorage.RemoveDirs(filepath.Join(prefix, "dists", distribution, component), progress)
err = publishedStorage.RemoveDirs(filepath.Join(rootPath, component), progress)
if err != nil {
return err
}

if multiDist {
for _, component := range removedComponents {
err = publishedStorage.RemoveDirs(filepath.Join(prefix, "pool", distribution, component), progress)
// Ensure that component does not exist in multi distribution pool
err = publishedStorage.RemoveDirs(filepath.Join(prefix, "pool", distribution, component), nil)
if err != nil {
return err
}
}

referencedFiles := map[string][]string{}

if published.MultiDist {
rootPath = filepath.Join(prefix, "pool", distribution)

// Get all referenced files by component for determining orphaned pool files.
for _, component := range publishedComponents {
packageList, err := NewPackageListFromRefList(published.RefList(component), collectionFactory.PackageCollection(), progress)
if err != nil {
return err
}

packageList.ForEach(func(p *Package) error {
poolDir, err := p.PoolDirectory()
if err != nil {
return err
}

for _, file := range p.Files() {
referencedFiles[component] = append(referencedFiles[component], filepath.Join(poolDir, file.Filename))
}

return nil
})
}
} else {
rootPath = filepath.Join(prefix, "pool")

// In case of a shared component pool directory, we must check, if a component is no longer referenced by any other
// published repository within the same prefix.
referencedComponents := map[string]struct{}{}
for _, p := range collection.list {
if p.Prefix == prefix && p.Storage == storage && !p.MultiDist {
for _, component := range p.Components() {
referencedComponents[component] = struct{}{}
}
}
}
}

components = make([]string, 0, len(updatedComponents)+len(removedComponents))
components = append(append(components, addedComponents...), updatedComponents...)
// Remove orphaned component pool directories in the prefix.
for _, component := range removedComponents {
_, exists := referencedComponents[component]
if !exists {
err := publishedStorage.RemoveDirs(filepath.Join(rootPath, component), progress)
if err != nil {
return err
}
}
}

referencedFiles, err := collection.listReferencedFilesByComponent(prefix, components, collectionFactory, progress)
if err != nil {
return err
// Get all referenced files by component for determining orphaned pool files.
referencedFiles, err = collection.listReferencedFilesByComponent(prefix, publishedComponents, collectionFactory, progress)
if err != nil {
return err
}
}

for _, component := range components {
for _, component := range updatedComponents {
if progress != nil {
progress.Printf("Cleaning up component %q in prefix %q...\n", component, prefix)
progress.Printf("Cleaning up component %q...\n", component)
}
sort.Strings(referencedFiles[component])

rootPath := filepath.Join(prefix, "pool", component)
existingFiles, err := publishedStorage.Filelist(rootPath)
path := filepath.Join(rootPath, component)
existingFiles, err := publishedStorage.Filelist(path)
if err != nil {
return err
}

sort.Strings(existingFiles)

filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles[component])
orphanedFiles := utils.StrSlicesSubstract(existingFiles, referencedFiles[component])

for _, file := range filesToDelete {
err = publishedStorage.Remove(filepath.Join(rootPath, file))
for _, file := range orphanedFiles {
err = publishedStorage.Remove(filepath.Join(path, file))
if err != nil {
return err
}
}
}

return nil
return err
}

// Remove removes published repository, cleaning up directories, files
Expand Down Expand Up @@ -1579,8 +1633,7 @@ func (collection *PublishedRepoCollection) Remove(publishedStorageProvider aptly
nil, collection.list[len(collection.list)-1], collection.list[:len(collection.list)-1]

if !skipCleanup && len(cleanComponents) > 0 {
err = collection.CleanupPrefixComponentFiles(publishedStorageProvider, repo, []string{}, cleanComponents, []string{},
collectionFactory, progress)
err = collection.CleanupPrefixComponentFiles(publishedStorageProvider, repo, cleanComponents, collectionFactory, progress)
if err != nil {
if !force {
return fmt.Errorf("cleanup failed, use -force-drop to override: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror10Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/d
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/rkward-dbgsym_0.7.5-1~bullseyecran.0_i386.deb
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/rkward_0.7.5-1~bullseyecran.0_amd64.deb
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/rkward_0.7.5-1~bullseyecran.0_i386.deb
Mirror `flat-src` has been successfully updated.
Mirror `flat-src` has been updated successfully.
Packages filtered: 110 -> 11.
gpgv: using RSA key 7BA040A510E4E66ED3743EC1B8F25A8A73EACF41
gpgv: Good signature from "Johannes Ranke <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror11FTPTest_gold
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Downloading: http://repo.aptly.info/system-tests/snapshot.debian.org/archive/deb
Downloading: http://repo.aptly.info/system-tests/snapshot.debian.org/archive/debian/20220201T025006Z/pool/main/s/sensible-utils/sensible-utils_0.0.9+deb9u1_all.deb
Downloading: http://repo.aptly.info/system-tests/snapshot.debian.org/archive/debian/20220201T025006Z/pool/main/s/sysvinit/sysvinit-utils_2.88dsf-59.9_i386.deb
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/snapshot.debian.org/archive/debian/20220201T025006Z/dists/stretch/InRelease
Mirror `stretch-main` has been successfully updated.
Mirror `stretch-main` has been updated successfully.
Packages filtered: 50604 -> 3.
Retrying 0 http://repo.aptly.info/system-tests/snapshot.debian.org/archive/debian/20220201T025006Z/dists/stretch/InRelease...
gpgv: issuer "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror12Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archi
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/pool/main/g/gnupg2/scdaemon_2.1.18-8~deb9u4_amd64.deb
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/pool/main/g/gnupg2/scdaemon_2.1.18-8~deb9u4_i386.deb
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/InRelease
Mirror `stretch` has been successfully updated.
Mirror `stretch` has been updated successfully.
Packages filtered: 78248 -> 20.
Retrying 0 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/InRelease...
gpgv: issuer "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror13Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/va
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish-dbg_3.0.3-1~wheezy_i386.deb
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish_3.0.3-1~wheezy_amd64.deb
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish_3.0.3-1~wheezy_i386.deb
Mirror `varnish` has been successfully updated.
Mirror `varnish` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror14Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Downloading & parsing package files...
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/dists/wheezy/Release
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/dists/wheezy/main/binary-amd64/Packages.bz2
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/dists/wheezy/main/binary-i386/Packages.bz2
Mirror `varnish` has been successfully updated.
Mirror `varnish` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror15Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Downloading & parsing package files...
Downloading https://dl.bintray.com/smira/deb/Packages.bz2...
Downloading https://dl.bintray.com/smira/deb/Release...
Downloading https://dl.bintray.com/smira/deb/libboost-program-options-dev_1.49.0.1_i386.deb...
Mirror `bintray` has been successfully updated.
Mirror `bintray` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror16Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Downloading & parsing package files...
Downloading https://dl.bintray.com/smira/deb/Packages.bz2...
Downloading https://dl.bintray.com/smira/deb/Release...
Downloading https://dl.bintray.com/smira/deb/libboost-program-options-dev_1.49.0.1_i386.deb...
Mirror `bintray` has been successfully updated.
Mirror `bintray` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror17Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Download queue: 0 items (0 B)
Downloading & parsing package files...
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/Release
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/main/binary-i386/Packages.gz
Mirror `stretch` has been successfully updated.
Mirror `stretch` has been updated successfully.
Packages filtered: 50604 -> 1.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror18Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Downloading & parsing package files...
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/Release
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/main/binary-i386/Packages.gz
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/pool/main/b/boost-defaults/libboost-program-options-dev_1.62.0.1_i386.deb
Mirror `stretch` has been successfully updated.
Mirror `stretch` has been updated successfully.
Packages filtered: 50604 -> 1.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror19Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Downloading: http://repo.aptly.info/system-tests/packages.pagerduty.com/pdagent/
Building download queue...
Download queue: 23 items (3.46 MiB)

Mirror `pagerduty` has been successfully updated.
Mirror `pagerduty` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror1Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/va
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish-dbg_3.0.3-1~wheezy_i386.deb
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish_3.0.3-1~wheezy_amd64.deb
Downloading: http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/pool/wheezy/main/v/varnish/varnish_3.0.3-1~wheezy_i386.deb
Mirror `varnish` has been successfully updated.
Mirror `varnish` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror20Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/d
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/Packages.bz2
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/r-cran-class_7.3-22-2~bullseyecran.0_amd64.deb
Downloading: http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/r-cran-class_7.3-22-2~bullseyecran.0_i386.deb
Mirror `flat` has been successfully updated.
Mirror `flat` has been updated successfully.
Packages filtered: 89 -> 2.
openpgp: Good signature from "Johannes Ranke <[email protected]>"
openpgp: RSA key ID B8F25A8A73EACF41
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror21Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Downloading: http://repo.aptly.info/system-tests/packages.pagerduty.com/pdagent/
Building download queue...
Download queue: 23 items (3.46 MiB)

Mirror `pagerduty` has been successfully updated.
Mirror `pagerduty` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror22Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Applying filter...
Building download queue...
Download queue: 0 items (0 B)

Mirror `libnvidia-container` has been successfully updated.
Mirror `libnvidia-container` has been updated successfully.
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror23Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archi
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/non-free/installer-s390x/current/images/SHA256SUMS
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/InRelease
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/non-free/installer-s390x/current/images/SHA256SUMS
Mirror `stretch` has been successfully updated.
Mirror `stretch` has been updated successfully.
Packages filtered: 49256 -> 1.
Retrying 0 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/InRelease...
Retrying 0 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/dists/stretch/non-free/installer-s390x/current/images/SHA256SUMS...
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/UpdateMirror24Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Downloading: http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/di
Downloading: http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/dists/trusty/restricted/installer-amd64/current/images/SHA256SUMS
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/dists/trusty/InRelease
Error (retrying): HTTP code 404 while fetching http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/dists/trusty/restricted/installer-amd64/current/images/SHA256SUMS
Mirror `trusty` has been successfully updated.
Mirror `trusty` has been updated successfully.
Packages filtered: 8616 -> 1.
Retrying 0 http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/dists/trusty/InRelease...
Retrying 0 http://repo.aptly.info/system-tests/us.archive.ubuntu.com/ubuntu/dists/trusty/restricted/installer-amd64/current/images/SHA256SUMS...
Expand Down
Loading

0 comments on commit cd49bf6

Please sign in to comment.