mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-07 22:20:24 +00:00
Refactoring: new packages console, http, Progress is interface.
This commit is contained in:
+14
-14
@@ -20,7 +20,7 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
// collect information about references packages...
|
||||
existingPackageRefs := debian.NewPackageRefList()
|
||||
|
||||
context.downloader.GetProgress().Printf("Loading mirrors and snapshots...\n")
|
||||
context.progress.Printf("Loading mirrors and snapshots...\n")
|
||||
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||
err = repoCollection.ForEach(func(repo *debian.RemoteRepo) error {
|
||||
err := repoCollection.LoadComplete(repo)
|
||||
@@ -48,14 +48,14 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
// ... and compare it to the list of all packages
|
||||
context.downloader.GetProgress().Printf("Loading list of all packages...\n")
|
||||
context.progress.Printf("Loading list of all packages...\n")
|
||||
packageCollection := debian.NewPackageCollection(context.database)
|
||||
allPackageRefs := packageCollection.AllPackageRefs()
|
||||
|
||||
toDelete := allPackageRefs.Substract(existingPackageRefs)
|
||||
|
||||
// delete packages that are no longer referenced
|
||||
context.downloader.GetProgress().Printf("Deleting unreferenced packages (%d)...\n", toDelete.Len())
|
||||
context.progress.Printf("Deleting unreferenced packages (%d)...\n", toDelete.Len())
|
||||
|
||||
context.database.StartBatch()
|
||||
err = toDelete.ForEach(func(ref []byte) error {
|
||||
@@ -71,9 +71,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
// now, build a list of files that should be present in Repository (package pool)
|
||||
context.downloader.GetProgress().Printf("Building list of files referenced by packages...\n")
|
||||
context.progress.Printf("Building list of files referenced by packages...\n")
|
||||
referencedFiles := make([]string, 0, existingPackageRefs.Len())
|
||||
context.downloader.GetProgress().InitBar(int64(existingPackageRefs.Len()), false)
|
||||
context.progress.InitBar(int64(existingPackageRefs.Len()), false)
|
||||
|
||||
err = existingPackageRefs.ForEach(func(key []byte) error {
|
||||
pkg, err := packageCollection.ByKey(key)
|
||||
@@ -85,7 +85,7 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
referencedFiles = append(referencedFiles, paths...)
|
||||
context.downloader.GetProgress().AddBar(1)
|
||||
context.progress.AddBar(1)
|
||||
|
||||
return nil
|
||||
})
|
||||
@@ -94,11 +94,11 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
sort.Strings(referencedFiles)
|
||||
context.downloader.GetProgress().ShutdownBar()
|
||||
context.progress.ShutdownBar()
|
||||
|
||||
// build a list of files in the package pool
|
||||
context.downloader.GetProgress().Printf("Building list of files in package pool...\n")
|
||||
existingFiles, err := context.packagePool.FilepathList(context.downloader.GetProgress())
|
||||
context.progress.Printf("Building list of files in package pool...\n")
|
||||
existingFiles, err := context.packagePool.FilepathList(context.progress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to collect file paths: %s", err)
|
||||
}
|
||||
@@ -107,10 +107,10 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles)
|
||||
|
||||
// delete files that are no longer referenced
|
||||
context.downloader.GetProgress().Printf("Deleting unreferenced files (%d)...\n", len(filesToDelete))
|
||||
context.progress.Printf("Deleting unreferenced files (%d)...\n", len(filesToDelete))
|
||||
|
||||
if len(filesToDelete) > 0 {
|
||||
context.downloader.GetProgress().InitBar(int64(len(filesToDelete)), false)
|
||||
context.progress.InitBar(int64(len(filesToDelete)), false)
|
||||
totalSize := int64(0)
|
||||
for _, file := range filesToDelete {
|
||||
size, err := context.packagePool.Remove(file)
|
||||
@@ -118,12 +118,12 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
context.downloader.GetProgress().AddBar(1)
|
||||
context.progress.AddBar(1)
|
||||
totalSize += size
|
||||
}
|
||||
context.downloader.GetProgress().ShutdownBar()
|
||||
context.progress.ShutdownBar()
|
||||
|
||||
context.downloader.GetProgress().Printf("Disk space freed: %.2f GiB...\n", float64(totalSize)/1024.0/1024.0/1024.0)
|
||||
context.progress.Printf("Disk space freed: %.2f GiB...\n", float64(totalSize)/1024.0/1024.0/1024.0)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user