mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-04 05:10:40 +00:00
Major refactoring: access to context happens in methods. #13
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ func ListPackagesRefList(reflist *debian.PackageRefList) (err error) {
|
||||
}
|
||||
|
||||
err = reflist.ForEach(func(key []byte) error {
|
||||
p, err2 := context.collectionFactory.PackageCollection().ByKey(key)
|
||||
p, err2 := context.CollectionFactory().PackageCollection().ByKey(key)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
+133
-67
@@ -19,7 +19,9 @@ import (
|
||||
)
|
||||
|
||||
// Common context shared by all commands
|
||||
var context struct {
|
||||
type AptlyContext struct {
|
||||
flags *flag.FlagSet
|
||||
|
||||
progress aptly.Progress
|
||||
downloader aptly.Downloader
|
||||
database database.Storage
|
||||
@@ -28,53 +30,146 @@ var context struct {
|
||||
collectionFactory *debian.CollectionFactory
|
||||
dependencyOptions int
|
||||
architecturesList []string
|
||||
flags *flag.FlagSet
|
||||
// Debug features
|
||||
fileCPUProfile *os.File
|
||||
fileMemProfile *os.File
|
||||
fileMemStats *os.File
|
||||
}
|
||||
|
||||
var context *AptlyContext
|
||||
|
||||
func (context *AptlyContext) Config() *utils.ConfigStructure {
|
||||
return &utils.Config
|
||||
}
|
||||
|
||||
func (context *AptlyContext) DependencyOptions() int {
|
||||
if context.dependencyOptions == -1 {
|
||||
context.dependencyOptions = 0
|
||||
if context.Config().DepFollowSuggests || context.flags.Lookup("dep-follow-suggests").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowSuggests
|
||||
}
|
||||
if context.Config().DepFollowRecommends || context.flags.Lookup("dep-follow-recommends").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowRecommends
|
||||
}
|
||||
if context.Config().DepFollowAllVariants || context.flags.Lookup("dep-follow-all-variants").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowAllVariants
|
||||
}
|
||||
if context.Config().DepFollowSource || context.flags.Lookup("dep-follow-source").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowSource
|
||||
}
|
||||
}
|
||||
|
||||
return context.dependencyOptions
|
||||
}
|
||||
|
||||
func (context *AptlyContext) ArchitecturesList() []string {
|
||||
if context.architecturesList == nil {
|
||||
context.architecturesList = context.Config().Architectures
|
||||
optionArchitectures := context.flags.Lookup("architectures").Value.String()
|
||||
if optionArchitectures != "" {
|
||||
context.architecturesList = strings.Split(optionArchitectures, ",")
|
||||
}
|
||||
}
|
||||
|
||||
return context.architecturesList
|
||||
}
|
||||
|
||||
func (context *AptlyContext) Progress() aptly.Progress {
|
||||
if context.progress == nil {
|
||||
context.progress = console.NewProgress()
|
||||
context.progress.Start()
|
||||
}
|
||||
|
||||
return context.progress
|
||||
}
|
||||
|
||||
func (context *AptlyContext) Downloader() aptly.Downloader {
|
||||
if context.downloader == nil {
|
||||
context.downloader = http.NewDownloader(context.Config().DownloadConcurrency, context.Progress())
|
||||
}
|
||||
|
||||
return context.downloader
|
||||
}
|
||||
|
||||
func (context *AptlyContext) DBPath() string {
|
||||
return filepath.Join(context.Config().RootDir, "db")
|
||||
}
|
||||
|
||||
func (context *AptlyContext) Database() (database.Storage, error) {
|
||||
if context.database == nil {
|
||||
var err error
|
||||
|
||||
context.database, err = database.OpenDB(context.DBPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't open database: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return context.database, nil
|
||||
}
|
||||
|
||||
func (context *AptlyContext) CollectionFactory() *debian.CollectionFactory {
|
||||
if context.collectionFactory == nil {
|
||||
db, err := context.Database()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
context.collectionFactory = debian.NewCollectionFactory(db)
|
||||
}
|
||||
|
||||
return context.collectionFactory
|
||||
}
|
||||
|
||||
func (context *AptlyContext) PackagePool() aptly.PackagePool {
|
||||
if context.packagePool == nil {
|
||||
context.packagePool = files.NewPackagePool(context.Config().RootDir)
|
||||
}
|
||||
|
||||
return context.packagePool
|
||||
}
|
||||
|
||||
func (context *AptlyContext) PublishedStorage() aptly.PublishedStorage {
|
||||
if context.publishedStorage == nil {
|
||||
context.publishedStorage = files.NewPublishedStorage(context.Config().RootDir)
|
||||
}
|
||||
|
||||
return context.publishedStorage
|
||||
}
|
||||
|
||||
// ShutdownContext shuts context down
|
||||
func ShutdownContext() {
|
||||
if aptly.EnableDebug {
|
||||
if context.fileMemProfile != nil {
|
||||
pprof.WriteHeapProfile(context.fileMemProfile)
|
||||
context.fileMemProfile.Close()
|
||||
context.fileMemProfile = nil
|
||||
}
|
||||
if context.fileCPUProfile != nil {
|
||||
pprof.StopCPUProfile()
|
||||
context.fileCPUProfile.Close()
|
||||
context.fileCPUProfile = nil
|
||||
}
|
||||
if context.fileMemProfile != nil {
|
||||
context.fileMemProfile.Close()
|
||||
context.fileMemProfile = nil
|
||||
}
|
||||
}
|
||||
if context.database != nil {
|
||||
context.database.Close()
|
||||
}
|
||||
if context.downloader != nil {
|
||||
context.downloader.Shutdown()
|
||||
}
|
||||
if context.progress != nil {
|
||||
context.progress.Shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
// InitContext initializes context with default settings
|
||||
func InitContext(flags *flag.FlagSet) error {
|
||||
var err error
|
||||
|
||||
context.flags = flags
|
||||
|
||||
context.dependencyOptions = 0
|
||||
if utils.Config.DepFollowSuggests || flags.Lookup("dep-follow-suggests").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowSuggests
|
||||
}
|
||||
if utils.Config.DepFollowRecommends || flags.Lookup("dep-follow-recommends").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowRecommends
|
||||
}
|
||||
if utils.Config.DepFollowAllVariants || flags.Lookup("dep-follow-all-variants").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowAllVariants
|
||||
}
|
||||
if utils.Config.DepFollowSource || flags.Lookup("dep-follow-source").Value.Get().(bool) {
|
||||
context.dependencyOptions |= debian.DepFollowSource
|
||||
}
|
||||
|
||||
context.architecturesList = utils.Config.Architectures
|
||||
optionArchitectures := flags.Lookup("architectures").Value.String()
|
||||
if optionArchitectures != "" {
|
||||
context.architecturesList = strings.Split(optionArchitectures, ",")
|
||||
}
|
||||
|
||||
context.progress = console.NewProgress()
|
||||
context.progress.Start()
|
||||
|
||||
context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)
|
||||
|
||||
context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't open database: %s", err)
|
||||
}
|
||||
|
||||
context.collectionFactory = debian.NewCollectionFactory(context.database)
|
||||
|
||||
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
||||
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
||||
context = &AptlyContext{flags: flags, dependencyOptions: -1}
|
||||
|
||||
if aptly.EnableDebug {
|
||||
cpuprofile := flags.Lookup("cpuprofile").Value.String()
|
||||
@@ -126,32 +221,3 @@ func InitContext(flags *flag.FlagSet) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ShutdownContext shuts context down
|
||||
func ShutdownContext() {
|
||||
if aptly.EnableDebug {
|
||||
if context.fileMemProfile != nil {
|
||||
pprof.WriteHeapProfile(context.fileMemProfile)
|
||||
context.fileMemProfile.Close()
|
||||
context.fileMemProfile = nil
|
||||
}
|
||||
if context.fileCPUProfile != nil {
|
||||
pprof.StopCPUProfile()
|
||||
context.fileCPUProfile.Close()
|
||||
context.fileCPUProfile = nil
|
||||
}
|
||||
if context.fileMemProfile != nil {
|
||||
context.fileMemProfile.Close()
|
||||
context.fileMemProfile = nil
|
||||
}
|
||||
}
|
||||
if context.database != nil {
|
||||
context.database.Close()
|
||||
}
|
||||
if context.downloader != nil {
|
||||
context.downloader.Shutdown()
|
||||
}
|
||||
if context.progress != nil {
|
||||
context.progress.Shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
+31
-29
@@ -20,9 +20,9 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
// collect information about references packages...
|
||||
existingPackageRefs := debian.NewPackageRefList()
|
||||
|
||||
context.progress.Printf("Loading mirrors, local repos and snapshots...\n")
|
||||
err = context.collectionFactory.RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
err := context.collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||
context.Progress().Printf("Loading mirrors, local repos and snapshots...\n")
|
||||
err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -35,8 +35,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -49,8 +49,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
err := context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -62,43 +62,45 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
// ... and compare it to the list of all packages
|
||||
context.progress.Printf("Loading list of all packages...\n")
|
||||
allPackageRefs := context.collectionFactory.PackageCollection().AllPackageRefs()
|
||||
context.Progress().Printf("Loading list of all packages...\n")
|
||||
allPackageRefs := context.CollectionFactory().PackageCollection().AllPackageRefs()
|
||||
|
||||
toDelete := allPackageRefs.Substract(existingPackageRefs)
|
||||
|
||||
// delete packages that are no longer referenced
|
||||
context.progress.Printf("Deleting unreferenced packages (%d)...\n", toDelete.Len())
|
||||
context.Progress().Printf("Deleting unreferenced packages (%d)...\n", toDelete.Len())
|
||||
|
||||
context.database.StartBatch()
|
||||
// database can't err as collection factory already constructed
|
||||
db, _ := context.Database()
|
||||
db.StartBatch()
|
||||
err = toDelete.ForEach(func(ref []byte) error {
|
||||
return context.collectionFactory.PackageCollection().DeleteByKey(ref)
|
||||
return context.CollectionFactory().PackageCollection().DeleteByKey(ref)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = context.database.FinishBatch()
|
||||
err = db.FinishBatch()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to write to DB: %s", err)
|
||||
}
|
||||
|
||||
// now, build a list of files that should be present in Repository (package pool)
|
||||
context.progress.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.progress.InitBar(int64(existingPackageRefs.Len()), false)
|
||||
context.Progress().InitBar(int64(existingPackageRefs.Len()), false)
|
||||
|
||||
err = existingPackageRefs.ForEach(func(key []byte) error {
|
||||
pkg, err2 := context.collectionFactory.PackageCollection().ByKey(key)
|
||||
pkg, err2 := context.CollectionFactory().PackageCollection().ByKey(key)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
paths, err2 := pkg.FilepathList(context.packagePool)
|
||||
paths, err2 := pkg.FilepathList(context.PackagePool())
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
referencedFiles = append(referencedFiles, paths...)
|
||||
context.progress.AddBar(1)
|
||||
context.Progress().AddBar(1)
|
||||
|
||||
return nil
|
||||
})
|
||||
@@ -107,11 +109,11 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
sort.Strings(referencedFiles)
|
||||
context.progress.ShutdownBar()
|
||||
context.Progress().ShutdownBar()
|
||||
|
||||
// build a list of files in the package pool
|
||||
context.progress.Printf("Building list of files in package pool...\n")
|
||||
existingFiles, err := context.packagePool.FilepathList(context.progress)
|
||||
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)
|
||||
}
|
||||
@@ -120,27 +122,27 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
||||
filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles)
|
||||
|
||||
// delete files that are no longer referenced
|
||||
context.progress.Printf("Deleting unreferenced files (%d)...\n", len(filesToDelete))
|
||||
context.Progress().Printf("Deleting unreferenced files (%d)...\n", len(filesToDelete))
|
||||
|
||||
if len(filesToDelete) > 0 {
|
||||
context.progress.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)
|
||||
size, err := context.PackagePool().Remove(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context.progress.AddBar(1)
|
||||
context.Progress().AddBar(1)
|
||||
totalSize += size
|
||||
}
|
||||
context.progress.ShutdownBar()
|
||||
context.Progress().ShutdownBar()
|
||||
|
||||
context.progress.Printf("Disk space freed: %s...\n", utils.HumanBytes(totalSize))
|
||||
context.Progress().Printf("Disk space freed: %s...\n", utils.HumanBytes(totalSize))
|
||||
}
|
||||
|
||||
context.progress.Printf("Compacting database...\n")
|
||||
err = context.database.CompactDB()
|
||||
context.Progress().Printf("Compacting database...\n")
|
||||
err = db.CompactDB()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
+8
-8
@@ -28,8 +28,8 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Loading mirrors...\n")
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
err := context.collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,8 +52,8 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Loading local repos...\n")
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,13 +75,13 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Loading snapshots...\n")
|
||||
|
||||
context.collectionFactory.SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
existingNodes[snapshot.UUID] = true
|
||||
return nil
|
||||
})
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
err := context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Loading published repos...\n")
|
||||
|
||||
context.collectionFactory.PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
graph.AddNode("aptly", graphvizEscape(repo.UUID), map[string]string{
|
||||
"shape": "Mrecord",
|
||||
"style": "filled",
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func getVerifier(flags *flag.FlagSet) (utils.Verifier, error) {
|
||||
if utils.Config.GpgDisableVerify || flags.Lookup("ignore-signatures").Value.Get().(bool) {
|
||||
if context.Config().GpgDisableVerify || flags.Lookup("ignore-signatures").Value.Get().(bool) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/smira/aptly/debian"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/smira/commander"
|
||||
"github.com/smira/flag"
|
||||
"strings"
|
||||
@@ -16,7 +15,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
downloadSources := utils.Config.DownloadSourcePackages || context.flags.Lookup("with-sources").Value.Get().(bool)
|
||||
downloadSources := context.Config().DownloadSourcePackages || context.flags.Lookup("with-sources").Value.Get().(bool)
|
||||
|
||||
var (
|
||||
mirrorName, archiveURL, distribution string
|
||||
@@ -33,7 +32,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||
archiveURL, distribution, components = args[1], args[2], args[3:]
|
||||
}
|
||||
|
||||
repo, err := debian.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.architecturesList, downloadSources)
|
||||
repo, err := debian.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.ArchitecturesList(), downloadSources)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create mirror: %s", err)
|
||||
}
|
||||
@@ -43,12 +42,12 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to initialize GPG verifier: %s", err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(context.downloader, verifier)
|
||||
err = repo.Fetch(context.Downloader(), verifier)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch mirror: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().Add(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().Add(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add mirror: %s", err)
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,14 +15,14 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.RemoteRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
force := context.flags.Lookup("force").Value.Get().(bool)
|
||||
if !force {
|
||||
snapshots := context.collectionFactory.SnapshotCollection().ByRemoteRepoSource(repo)
|
||||
snapshots := context.CollectionFactory().SnapshotCollection().ByRemoteRepoSource(repo)
|
||||
|
||||
if len(snapshots) > 0 {
|
||||
fmt.Printf("Mirror `%s` was used to create following snapshots:\n", repo.Name)
|
||||
@@ -34,7 +34,7 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().Drop(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().Drop(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,11 +14,11 @@ func aptlyMirrorList(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.collectionFactory.RemoteRepoCollection().Len() > 0 {
|
||||
if context.CollectionFactory().RemoteRepoCollection().Len() > 0 {
|
||||
fmt.Printf("List of mirrors:\n")
|
||||
repos := make([]string, context.collectionFactory.RemoteRepoCollection().Len())
|
||||
repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len())
|
||||
i := 0
|
||||
context.collectionFactory.RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *debian.RemoteRepo) error {
|
||||
repos[i] = repo.String()
|
||||
i++
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -17,12 +17,12 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.RemoteRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.RemoteRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update: %s", err)
|
||||
}
|
||||
@@ -32,22 +32,22 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to initialize GPG verifier: %s", err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(context.downloader, verifier)
|
||||
err = repo.Fetch(context.Downloader(), verifier)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update: %s", err)
|
||||
}
|
||||
|
||||
err = repo.Download(context.progress, context.downloader, context.collectionFactory, context.packagePool, ignoreMismatch)
|
||||
err = repo.Download(context.Progress(), context.Downloader(), context.CollectionFactory(), context.PackagePool(), ignoreMismatch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to update: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().Update(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
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 successfully updated.\n", repo.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func getSigner(flags *flag.FlagSet) (utils.Signer, error) {
|
||||
if flags.Lookup("skip-signing").Value.Get().(bool) || utils.Config.GpgDisableSign {
|
||||
if flags.Lookup("skip-signing").Value.Get().(bool) || context.Config().GpgDisableSign {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ func aptlyPublishDrop(cmd *commander.Command, args []string) error {
|
||||
prefix = args[1]
|
||||
}
|
||||
|
||||
err = context.collectionFactory.PublishedRepoCollection().Remove(context.publishedStorage, prefix, distribution)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().Remove(context.PublishedStorage(), prefix, distribution)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to remove: %s", err)
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,15 +14,15 @@ func aptlyPublishList(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.collectionFactory.PublishedRepoCollection().Len() == 0 {
|
||||
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
|
||||
fmt.Printf("No snapshots have been published. Publish a snapshot by running `aptly publish snapshot ...`.\n")
|
||||
return err
|
||||
}
|
||||
|
||||
published := make([]string, 0, context.collectionFactory.PublishedRepoCollection().Len())
|
||||
published := make([]string, 0, context.CollectionFactory().PublishedRepoCollection().Len())
|
||||
|
||||
err = context.collectionFactory.PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
err := context.collectionFactory.PublishedRepoCollection().LoadComplete(repo, context.collectionFactory)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+16
-16
@@ -31,12 +31,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||
)
|
||||
|
||||
if cmd.Name() == "snapshot" {
|
||||
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
|
||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
@@ -44,12 +44,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||
source = snapshot
|
||||
message = fmt.Sprintf("Snapshot %s", snapshot.Name)
|
||||
} else if cmd.Name() == "repo" {
|
||||
localRepo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||
localRepo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(localRepo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(localRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
@@ -63,14 +63,14 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||
component := context.flags.Lookup("component").Value.String()
|
||||
distribution := context.flags.Lookup("distribution").Value.String()
|
||||
|
||||
published, err := debian.NewPublishedRepo(prefix, distribution, component, context.architecturesList, source, context.collectionFactory)
|
||||
published, err := debian.NewPublishedRepo(prefix, distribution, component, context.ArchitecturesList(), source, context.CollectionFactory())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
|
||||
duplicate := context.collectionFactory.PublishedRepoCollection().CheckDuplicate(published)
|
||||
duplicate := context.CollectionFactory().PublishedRepoCollection().CheckDuplicate(published)
|
||||
if duplicate != nil {
|
||||
context.collectionFactory.PublishedRepoCollection().LoadComplete(duplicate, context.collectionFactory)
|
||||
context.CollectionFactory().PublishedRepoCollection().LoadComplete(duplicate, context.CollectionFactory())
|
||||
return fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
|
||||
}
|
||||
|
||||
@@ -79,12 +79,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to initialize GPG signer: %s", err)
|
||||
}
|
||||
|
||||
err = published.Publish(context.packagePool, context.publishedStorage, context.collectionFactory, signer, context.progress)
|
||||
err = published.Publish(context.PackagePool(), context.PublishedStorage(), context.CollectionFactory(), signer, context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to publish: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.PublishedRepoCollection().Add(published)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().Add(published)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save to DB: %s", err)
|
||||
}
|
||||
@@ -96,15 +96,15 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||
prefix += "/"
|
||||
}
|
||||
|
||||
context.progress.Printf("\n%s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||
message, context.publishedStorage.PublicPath())
|
||||
context.progress.Printf("Now you can add following line to apt sources:\n")
|
||||
context.progress.Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
context.Progress().Printf("\n%s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||
message, context.PublishedStorage().PublicPath())
|
||||
context.Progress().Printf("Now you can add following line to apt sources:\n")
|
||||
context.Progress().Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
if utils.StrSliceHasItem(published.Architectures, "source") {
|
||||
context.progress.Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
context.Progress().Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||
}
|
||||
context.progress.Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
||||
context.progress.Printf("\nYou can also use `aptly serve` to publish your repositories over HTTP quickly.\n")
|
||||
context.Progress().Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
||||
context.Progress().Printf("\nYou can also use `aptly serve` to publish your repositories over HTTP quickly.\n")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
+16
-16
@@ -23,19 +23,19 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
|
||||
verifier := &utils.GpgVerifier{}
|
||||
|
||||
repo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add: %s", err)
|
||||
}
|
||||
|
||||
context.progress.Printf("Loading packages...\n")
|
||||
context.Progress().Printf("Loading packages...\n")
|
||||
|
||||
list, err := debian.NewPackageListFromRefList(repo.RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
list, err := debian.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
for _, location := range args[1:] {
|
||||
info, err2 := os.Stat(location)
|
||||
if err2 != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to process %s: %s@|", location, err2)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to process %s: %s@|", location, err2)
|
||||
continue
|
||||
}
|
||||
if info.IsDir() {
|
||||
@@ -67,7 +67,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
if strings.HasSuffix(info.Name(), ".deb") || strings.HasSuffix(info.Name(), ".dsc") {
|
||||
packageFiles = append(packageFiles, location)
|
||||
} else {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unknwon file extenstion: %s@|", location)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unknwon file extenstion: %s@|", location)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
p = debian.NewPackageFromControlFile(stanza)
|
||||
}
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to read file %s: %s@|", file, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to read file %s: %s@|", file, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
p.UpdateFiles([]debian.PackageFile{debian.PackageFile{Filename: filepath.Base(file), Checksums: checksums}})
|
||||
}
|
||||
|
||||
err = context.packagePool.Import(file, checksums.MD5)
|
||||
err = context.PackagePool().Import(file, checksums.MD5)
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", file, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", file, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
sourceFile := filepath.Join(filepath.Dir(file), filepath.Base(f.Filename))
|
||||
err = context.packagePool.Import(sourceFile, f.Checksums.MD5)
|
||||
err = context.PackagePool().Import(sourceFile, f.Checksums.MD5)
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", sourceFile, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", sourceFile, err)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -142,25 +142,25 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
err = context.collectionFactory.PackageCollection().Update(p)
|
||||
err = context.CollectionFactory().PackageCollection().Update(p)
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to save package %s: %s@|", p, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to save package %s: %s@|", p, err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = list.Add(p)
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Unable to add package to repo %s: %s@|", p, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to add package to repo %s: %s@|", p, err)
|
||||
continue
|
||||
}
|
||||
|
||||
context.progress.ColoredPrintf("@g[+]@| %s added@|", p)
|
||||
context.Progress().ColoredPrintf("@g[+]@| %s added@|", p)
|
||||
processedFiles = append(processedFiles, candidateProcessedFiles...)
|
||||
}
|
||||
|
||||
repo.UpdateRefList(debian.NewPackageRefListFromPackageList(list))
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Update(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save: %s", err)
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error {
|
||||
repo.DefaultDistribution = context.flags.Lookup("distribution").Value.String()
|
||||
repo.DefaultComponent = context.flags.Lookup("component").Value.String()
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Add(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Add(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add local repo: %s", err)
|
||||
}
|
||||
|
||||
+5
-5
@@ -15,16 +15,16 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
published := context.collectionFactory.PublishedRepoCollection().ByLocalRepo(repo)
|
||||
published := context.CollectionFactory().PublishedRepoCollection().ByLocalRepo(repo)
|
||||
if len(published) > 0 {
|
||||
fmt.Printf("Local repo `%s` is published currently:\n", repo.Name)
|
||||
for _, repo := range published {
|
||||
err = context.collectionFactory.PublishedRepoCollection().LoadComplete(repo, context.collectionFactory)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load published: %s", err)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
||||
|
||||
force := context.flags.Lookup("force").Value.Get().(bool)
|
||||
if !force {
|
||||
snapshots := context.collectionFactory.SnapshotCollection().ByLocalRepoSource(repo)
|
||||
snapshots := context.CollectionFactory().SnapshotCollection().ByLocalRepoSource(repo)
|
||||
|
||||
if len(snapshots) > 0 {
|
||||
fmt.Printf("Local repo `%s` was used to create following snapshots:\n", repo.Name)
|
||||
@@ -48,7 +48,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Drop(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Drop(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,12 +13,12 @@ func aptlyRepoEdit(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
repo, err := context.collectionFactory.LocalRepoCollection().ByName(args[0])
|
||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to edit: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to edit: %s", err)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func aptlyRepoEdit(cmd *commander.Command, args []string) error {
|
||||
repo.DefaultComponent = context.flags.Lookup("component").Value.String()
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Update(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to edit: %s", err)
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,12 +14,12 @@ func aptlyRepoList(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.collectionFactory.LocalRepoCollection().Len() > 0 {
|
||||
if context.CollectionFactory().LocalRepoCollection().Len() > 0 {
|
||||
fmt.Printf("List of mirrors:\n")
|
||||
repos := make([]string, context.collectionFactory.LocalRepoCollection().Len())
|
||||
repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len())
|
||||
i := 0
|
||||
context.collectionFactory.LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *debian.LocalRepo) error {
|
||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+16
-16
@@ -17,12 +17,12 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
|
||||
command := cmd.Name()
|
||||
|
||||
dstRepo, err := context.collectionFactory.LocalRepoCollection().ByName(args[1])
|
||||
dstRepo, err := context.CollectionFactory().LocalRepoCollection().ByName(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(dstRepo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(dstRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
)
|
||||
|
||||
if command == "copy" || command == "move" {
|
||||
srcRepo, err = context.collectionFactory.LocalRepoCollection().ByName(args[0])
|
||||
srcRepo, err = context.CollectionFactory().LocalRepoCollection().ByName(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to %s: source and destination are the same", command)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(srcRepo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(srcRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
@@ -51,12 +51,12 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
} else if command == "import" {
|
||||
var srcRemoteRepo *debian.RemoteRepo
|
||||
|
||||
srcRemoteRepo, err = context.collectionFactory.RemoteRepoCollection().ByName(args[0])
|
||||
srcRemoteRepo, err = context.CollectionFactory().RemoteRepoCollection().ByName(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().LoadComplete(srcRemoteRepo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(srcRemoteRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
@@ -70,14 +70,14 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
panic("unexpected command")
|
||||
}
|
||||
|
||||
context.progress.Printf("Loading packages...\n")
|
||||
context.Progress().Printf("Loading packages...\n")
|
||||
|
||||
dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
|
||||
srcList, err := debian.NewPackageListFromRefList(srcRefList, context.collectionFactory.PackageCollection(), context.progress)
|
||||
srcList, err := debian.NewPackageListFromRefList(srcRefList, context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -92,8 +92,8 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
dstList.PrepareIndex()
|
||||
|
||||
// Calculate architectures
|
||||
if len(context.architecturesList) > 0 {
|
||||
architecturesList = context.architecturesList
|
||||
if len(context.ArchitecturesList()) > 0 {
|
||||
architecturesList = context.ArchitecturesList()
|
||||
} else {
|
||||
architecturesList = dstList.Architectures(false)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
toProcess, err := srcList.Filter(args[2:], withDeps, dstList, context.dependencyOptions, architecturesList)
|
||||
toProcess, err := srcList.Filter(args[2:], withDeps, dstList, context.DependencyOptions(), architecturesList)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to %s: %s", command, err)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
if command == "move" {
|
||||
srcList.Remove(p)
|
||||
}
|
||||
context.progress.ColoredPrintf("@g[o]@| %s %s", p, verb)
|
||||
context.Progress().ColoredPrintf("@g[o]@| %s %s", p, verb)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -137,11 +137,11 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
if context.flags.Lookup("dry-run").Value.Get().(bool) {
|
||||
context.progress.Printf("\nChanges not saved, as dry run has been requested.\n")
|
||||
context.Progress().Printf("\nChanges not saved, as dry run has been requested.\n")
|
||||
} else {
|
||||
dstRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(dstList))
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Update(dstRepo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(dstRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save: %s", err)
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||
if command == "move" {
|
||||
srcRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(srcList))
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Update(srcRepo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(srcRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save: %s", err)
|
||||
}
|
||||
|
||||
+7
-7
@@ -16,19 +16,19 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to remove: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to remove: %s", err)
|
||||
}
|
||||
|
||||
context.progress.Printf("Loading packages...\n")
|
||||
context.Progress().Printf("Loading packages...\n")
|
||||
|
||||
list, err := debian.NewPackageListFromRefList(repo.RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
list, err := debian.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -41,16 +41,16 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error {
|
||||
|
||||
toRemove.ForEach(func(p *debian.Package) error {
|
||||
list.Remove(p)
|
||||
context.progress.ColoredPrintf("@r[-]@| %s removed", p)
|
||||
context.Progress().ColoredPrintf("@r[-]@| %s removed", p)
|
||||
return nil
|
||||
})
|
||||
|
||||
if context.flags.Lookup("dry-run").Value.Get().(bool) {
|
||||
context.progress.Printf("\nChanges not saved, as dry run has been requested.\n")
|
||||
context.Progress().Printf("\nChanges not saved, as dry run has been requested.\n")
|
||||
} else {
|
||||
repo.UpdateRefList(debian.NewPackageRefListFromPackageList(list))
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().Update(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save: %s", err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,12 +15,12 @@ func aptlyRepoShow(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
repo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
|
||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
+8
-7
@@ -15,7 +15,7 @@ import (
|
||||
func aptlyServe(cmd *commander.Command, args []string) error {
|
||||
var err error
|
||||
|
||||
if context.collectionFactory.PublishedRepoCollection().Len() == 0 {
|
||||
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
|
||||
fmt.Printf("No published repositories, unable to serve.\n")
|
||||
return nil
|
||||
}
|
||||
@@ -37,11 +37,11 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Serving published repositories, recommended apt sources list:\n\n")
|
||||
|
||||
sources := make(sort.StringSlice, 0, context.collectionFactory.PublishedRepoCollection().Len())
|
||||
published := make(map[string]*debian.PublishedRepo, context.collectionFactory.PublishedRepoCollection().Len())
|
||||
sources := make(sort.StringSlice, 0, context.CollectionFactory().PublishedRepoCollection().Len())
|
||||
published := make(map[string]*debian.PublishedRepo, context.CollectionFactory().PublishedRepoCollection().Len())
|
||||
|
||||
err = context.collectionFactory.PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
err := context.collectionFactory.PublishedRepoCollection().LoadComplete(repo, context.collectionFactory)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *debian.PublishedRepo) error {
|
||||
err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -77,11 +77,12 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
context.database.Close()
|
||||
publicPath := context.PublishedStorage().PublicPath()
|
||||
ShutdownContext()
|
||||
|
||||
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)
|
||||
|
||||
err = http.ListenAndServe(listen, http.FileServer(http.Dir(context.publishedStorage.PublicPath())))
|
||||
err = http.ListenAndServe(listen, http.FileServer(http.Dir(publicPath)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to serve: %s", err)
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
||||
|
||||
repoName, snapshotName := args[3], args[0]
|
||||
|
||||
repo, err = context.collectionFactory.RemoteRepoCollection().ByName(repoName)
|
||||
repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(repoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
@@ -38,12 +38,12 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
||||
|
||||
localRepoName, snapshotName := args[3], args[0]
|
||||
|
||||
repo, err = context.collectionFactory.LocalRepoCollection().ByName(localRepoName)
|
||||
repo, err = context.CollectionFactory().LocalRepoCollection().ByName(localRepoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().Add(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().Add(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add snapshot: %s", err)
|
||||
}
|
||||
|
||||
@@ -16,37 +16,37 @@ func aptlySnapshotDiff(cmd *commander.Command, args []string) error {
|
||||
onlyMatching := context.flags.Lookup("only-matching").Value.Get().(bool)
|
||||
|
||||
// Load <name-a> snapshot
|
||||
snapshotA, err := context.collectionFactory.SnapshotCollection().ByName(args[0])
|
||||
snapshotA, err := context.CollectionFactory().SnapshotCollection().ByName(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot A: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshotA)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshotA)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot A: %s", err)
|
||||
}
|
||||
|
||||
// Load <name-b> snapshot
|
||||
snapshotB, err := context.collectionFactory.SnapshotCollection().ByName(args[1])
|
||||
snapshotB, err := context.CollectionFactory().SnapshotCollection().ByName(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot B: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshotB)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshotB)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot B: %s", err)
|
||||
}
|
||||
|
||||
// Calculate diff
|
||||
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), context.collectionFactory.PackageCollection())
|
||||
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), context.CollectionFactory().PackageCollection())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to calculate diff: %s", err)
|
||||
}
|
||||
|
||||
if len(diff) == 0 {
|
||||
context.progress.Printf("Snapshots are identical.\n")
|
||||
context.Progress().Printf("Snapshots are identical.\n")
|
||||
} else {
|
||||
context.progress.Printf(" Arch | Package | Version in A | Version in B\n")
|
||||
context.Progress().Printf(" Arch | Package | Version in A | Version in B\n")
|
||||
for _, pdiff := range diff {
|
||||
if onlyMatching && (pdiff.Left == nil || pdiff.Right == nil) {
|
||||
continue
|
||||
@@ -80,7 +80,7 @@ func aptlySnapshotDiff(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
context.progress.ColoredPrintf(code+" %-6s | %-40s | %-40s | %-40s", arch, pkg, verA, verB)
|
||||
context.Progress().ColoredPrintf(code+" %-6s | %-40s | %-40s | %-40s", arch, pkg, verA, verB)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,17 +15,17 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
|
||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
published := context.collectionFactory.PublishedRepoCollection().BySnapshot(snapshot)
|
||||
published := context.CollectionFactory().PublishedRepoCollection().BySnapshot(snapshot)
|
||||
|
||||
if len(published) > 0 {
|
||||
fmt.Printf("Snapshot `%s` is published currently:\n", snapshot.Name)
|
||||
for _, repo := range published {
|
||||
err = context.collectionFactory.PublishedRepoCollection().LoadComplete(repo, context.collectionFactory)
|
||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load published: %s", err)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
||||
|
||||
force := context.flags.Lookup("force").Value.Get().(bool)
|
||||
if !force {
|
||||
snapshots := context.collectionFactory.SnapshotCollection().BySnapshotSource(snapshot)
|
||||
snapshots := context.CollectionFactory().SnapshotCollection().BySnapshotSource(snapshot)
|
||||
if len(snapshots) > 0 {
|
||||
fmt.Printf("Snapshot `%s` was used as a source in following snapshots:\n", snapshot.Name)
|
||||
for _, snap := range snapshots {
|
||||
@@ -48,7 +48,7 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().Drop(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().Drop(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.collectionFactory.SnapshotCollection().Len() > 0 {
|
||||
if context.CollectionFactory().SnapshotCollection().Len() > 0 {
|
||||
fmt.Printf("List of snapshots:\n")
|
||||
|
||||
snapshots := make([]string, context.collectionFactory.SnapshotCollection().Len())
|
||||
snapshots := make([]string, context.CollectionFactory().SnapshotCollection().Len())
|
||||
|
||||
i := 0
|
||||
context.collectionFactory.SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *debian.Snapshot) error {
|
||||
snapshots[i] = snapshot.String()
|
||||
i++
|
||||
return nil
|
||||
|
||||
@@ -17,12 +17,12 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
||||
sources := make([]*debian.Snapshot, len(args)-1)
|
||||
|
||||
for i := 0; i < len(args)-1; i++ {
|
||||
sources[i], err = context.collectionFactory.SnapshotCollection().ByName(args[i+1])
|
||||
sources[i], err = context.CollectionFactory().SnapshotCollection().ByName(args[i+1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(sources[i])
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(sources[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load snapshot: %s", err)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
||||
destination := debian.NewSnapshotFromRefList(args[0], sources, result,
|
||||
fmt.Sprintf("Merged from sources: %s", strings.Join(sourceDescription, ", ")))
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().Add(destination)
|
||||
err = context.CollectionFactory().SnapshotCollection().Add(destination)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
|
||||
+19
-19
@@ -20,51 +20,51 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||
noRemove := context.flags.Lookup("no-remove").Value.Get().(bool)
|
||||
|
||||
// Load <name> snapshot
|
||||
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(args[0])
|
||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to pull: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to pull: %s", err)
|
||||
}
|
||||
|
||||
// Load <source> snapshot
|
||||
source, err := context.collectionFactory.SnapshotCollection().ByName(args[1])
|
||||
source, err := context.CollectionFactory().SnapshotCollection().ByName(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to pull: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(source)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to pull: %s", err)
|
||||
}
|
||||
|
||||
context.progress.Printf("Dependencies would be pulled into snapshot:\n %s\nfrom snapshot:\n %s\nand result would be saved as new snapshot %s.\n",
|
||||
context.Progress().Printf("Dependencies would be pulled into snapshot:\n %s\nfrom snapshot:\n %s\nand result would be saved as new snapshot %s.\n",
|
||||
snapshot, source, args[2])
|
||||
|
||||
// Convert snapshot to package list
|
||||
context.progress.Printf("Loading packages (%d)...\n", snapshot.RefList().Len()+source.RefList().Len())
|
||||
packageList, err := debian.NewPackageListFromRefList(snapshot.RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
context.Progress().Printf("Loading packages (%d)...\n", snapshot.RefList().Len()+source.RefList().Len())
|
||||
packageList, err := debian.NewPackageListFromRefList(snapshot.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
|
||||
sourcePackageList, err := debian.NewPackageListFromRefList(source.RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
sourcePackageList, err := debian.NewPackageListFromRefList(source.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
|
||||
context.progress.Printf("Building indexes...\n")
|
||||
context.Progress().Printf("Building indexes...\n")
|
||||
packageList.PrepareIndex()
|
||||
sourcePackageList.PrepareIndex()
|
||||
|
||||
// Calculate architectures
|
||||
var architecturesList []string
|
||||
|
||||
if len(context.architecturesList) > 0 {
|
||||
architecturesList = context.architecturesList
|
||||
if len(context.ArchitecturesList()) > 0 {
|
||||
architecturesList = context.ArchitecturesList()
|
||||
} else {
|
||||
architecturesList = packageList.Architectures(false)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||
// Search for package that can satisfy dependencies
|
||||
pkg := sourcePackageList.Search(dep)
|
||||
if pkg == nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Dependency %s can't be satisfied with source %s@|", &dep, source)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Dependency %s can't be satisfied with source %s@|", &dep, source)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||
// Remove all packages with the same name and architecture
|
||||
for p := packageList.Search(debian.Dependency{Architecture: pkg.Architecture, Pkg: pkg.Name}); p != nil; {
|
||||
packageList.Remove(p)
|
||||
context.progress.ColoredPrintf("@r[-]@| %s removed", p)
|
||||
context.Progress().ColoredPrintf("@r[-]@| %s removed", p)
|
||||
p = packageList.Search(debian.Dependency{Architecture: pkg.Architecture, Pkg: pkg.Name})
|
||||
}
|
||||
}
|
||||
|
||||
// Add new discovered package
|
||||
packageList.Add(pkg)
|
||||
context.progress.ColoredPrintf("@g[+]@| %s added", pkg)
|
||||
context.Progress().ColoredPrintf("@g[+]@| %s added", pkg)
|
||||
|
||||
if noDeps {
|
||||
continue
|
||||
@@ -125,9 +125,9 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||
pL.Add(pkg)
|
||||
|
||||
var missing []debian.Dependency
|
||||
missing, err = pL.VerifyDependencies(context.dependencyOptions, []string{arch}, packageList, nil)
|
||||
missing, err = pL.VerifyDependencies(context.DependencyOptions(), []string{arch}, packageList, nil)
|
||||
if err != nil {
|
||||
context.progress.ColoredPrintf("@y[!]@| @!Error while verifying dependencies for pkg %s: %s@|", pkg, err)
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Error while verifying dependencies for pkg %s: %s@|", pkg, err)
|
||||
}
|
||||
|
||||
// Append missing dependencies to the list of dependencies to satisfy
|
||||
@@ -148,18 +148,18 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
if context.flags.Lookup("dry-run").Value.Get().(bool) {
|
||||
context.progress.Printf("\nNot creating snapshot, as dry run was requested.\n")
|
||||
context.Progress().Printf("\nNot creating snapshot, as dry run was requested.\n")
|
||||
} else {
|
||||
// Create <destination> snapshot
|
||||
destination := debian.NewSnapshotFromPackageList(args[2], []*debian.Snapshot{snapshot, source}, packageList,
|
||||
fmt.Sprintf("Pulled into '%s' with '%s' as source, pull request was: '%s'", snapshot.Name, source.Name, strings.Join(args[3:], " ")))
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().Add(destination)
|
||||
err = context.CollectionFactory().SnapshotCollection().Add(destination)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||
}
|
||||
|
||||
context.progress.Printf("\nSnapshot %s successfully created.\nYou can run 'aptly publish snapshot %s' to publish snapshot as Debian repository.\n", destination.Name, destination.Name)
|
||||
context.Progress().Printf("\nSnapshot %s successfully created.\nYou can run 'aptly publish snapshot %s' to publish snapshot as Debian repository.\n", destination.Name, destination.Name)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
||||
|
||||
name := args[0]
|
||||
|
||||
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
|
||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to show: %s", err)
|
||||
}
|
||||
|
||||
+12
-12
@@ -16,20 +16,20 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||
|
||||
snapshots := make([]*debian.Snapshot, len(args))
|
||||
for i := range snapshots {
|
||||
snapshots[i], err = context.collectionFactory.SnapshotCollection().ByName(args[i])
|
||||
snapshots[i], err = context.CollectionFactory().SnapshotCollection().ByName(args[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to verify: %s", err)
|
||||
}
|
||||
|
||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshots[i])
|
||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshots[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to verify: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
context.progress.Printf("Loading packages...\n")
|
||||
context.Progress().Printf("Loading packages...\n")
|
||||
|
||||
packageList, err := debian.NewPackageListFromRefList(snapshots[0].RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
packageList, err := debian.NewPackageListFromRefList(snapshots[0].RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||
|
||||
var pL *debian.PackageList
|
||||
for i := 1; i < len(snapshots); i++ {
|
||||
pL, err = debian.NewPackageListFromRefList(snapshots[i].RefList(), context.collectionFactory.PackageCollection(), context.progress)
|
||||
pL, err = debian.NewPackageListFromRefList(snapshots[i].RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
||||
if err != nil {
|
||||
fmt.Errorf("unable to load packages: %s", err)
|
||||
}
|
||||
@@ -57,8 +57,8 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||
|
||||
var architecturesList []string
|
||||
|
||||
if len(context.architecturesList) > 0 {
|
||||
architecturesList = context.architecturesList
|
||||
if len(context.ArchitecturesList()) > 0 {
|
||||
architecturesList = context.ArchitecturesList()
|
||||
} else {
|
||||
architecturesList = packageList.Architectures(true)
|
||||
}
|
||||
@@ -67,17 +67,17 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to determine list of architectures, please specify explicitly")
|
||||
}
|
||||
|
||||
context.progress.Printf("Verifying...\n")
|
||||
context.Progress().Printf("Verifying...\n")
|
||||
|
||||
missing, err := packageList.VerifyDependencies(context.dependencyOptions, architecturesList, sourcePackageList, context.progress)
|
||||
missing, err := packageList.VerifyDependencies(context.DependencyOptions(), architecturesList, sourcePackageList, context.Progress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to verify dependencies: %s", err)
|
||||
}
|
||||
|
||||
if len(missing) == 0 {
|
||||
context.progress.Printf("All dependencies are satisfied.\n")
|
||||
context.Progress().Printf("All dependencies are satisfied.\n")
|
||||
} else {
|
||||
context.progress.Printf("Missing dependencies (%d):\n", len(missing))
|
||||
context.Progress().Printf("Missing dependencies (%d):\n", len(missing))
|
||||
deps := make([]string, len(missing))
|
||||
i := 0
|
||||
for _, dep := range missing {
|
||||
@@ -88,7 +88,7 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||
sort.Strings(deps)
|
||||
|
||||
for _, dep := range deps {
|
||||
context.progress.Printf(" %s\n", dep)
|
||||
context.Progress().Printf(" %s\n", dep)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user