mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-15 07:00:52 +00:00
New upstream version 1.5.0+ds1
This commit is contained in:
+80
-23
@@ -15,14 +15,17 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aptly-dev/aptly/aptly"
|
||||
"github.com/aptly-dev/aptly/azure"
|
||||
"github.com/aptly-dev/aptly/console"
|
||||
"github.com/aptly-dev/aptly/database"
|
||||
"github.com/aptly-dev/aptly/database/goleveldb"
|
||||
"github.com/aptly-dev/aptly/deb"
|
||||
"github.com/aptly-dev/aptly/files"
|
||||
"github.com/aptly-dev/aptly/http"
|
||||
"github.com/aptly-dev/aptly/pgp"
|
||||
"github.com/aptly-dev/aptly/s3"
|
||||
"github.com/aptly-dev/aptly/swift"
|
||||
"github.com/aptly-dev/aptly/task"
|
||||
"github.com/aptly-dev/aptly/utils"
|
||||
"github.com/smira/commander"
|
||||
"github.com/smira/flag"
|
||||
@@ -39,10 +42,10 @@ type AptlyContext struct {
|
||||
|
||||
progress aptly.Progress
|
||||
downloader aptly.Downloader
|
||||
taskList *task.List
|
||||
database database.Storage
|
||||
packagePool aptly.PackagePool
|
||||
publishedStorages map[string]aptly.PublishedStorage
|
||||
collectionFactory *deb.CollectionFactory
|
||||
dependencyOptions int
|
||||
architecturesList []string
|
||||
// Debug features
|
||||
@@ -199,26 +202,66 @@ func (context *AptlyContext) _progress() aptly.Progress {
|
||||
return context.progress
|
||||
}
|
||||
|
||||
// NewDownloader returns instance of new downloader with given progress
|
||||
func (context *AptlyContext) NewDownloader(progress aptly.Progress) aptly.Downloader {
|
||||
context.Lock()
|
||||
defer context.Unlock()
|
||||
|
||||
return context.newDownloader(progress)
|
||||
}
|
||||
|
||||
// NewDownloader returns instance of new downloader with given progress without locking
|
||||
// so it can be used for internal usage.
|
||||
func (context *AptlyContext) newDownloader(progress aptly.Progress) aptly.Downloader {
|
||||
var downloadLimit int64
|
||||
limitFlag := context.flags.Lookup("download-limit")
|
||||
if limitFlag != nil {
|
||||
downloadLimit = limitFlag.Value.Get().(int64)
|
||||
}
|
||||
if downloadLimit == 0 {
|
||||
downloadLimit = context.config().DownloadLimit
|
||||
}
|
||||
maxTries := context.config().DownloadRetries + 1
|
||||
maxTriesFlag := context.flags.Lookup("max-tries")
|
||||
if maxTriesFlag != nil {
|
||||
// If flag is defined prefer it to global setting
|
||||
maxTries = maxTriesFlag.Value.Get().(int)
|
||||
}
|
||||
var downloader string = context.config().Downloader
|
||||
downloaderFlag := context.flags.Lookup("downloader")
|
||||
if downloaderFlag != nil {
|
||||
downloader = downloaderFlag.Value.String()
|
||||
}
|
||||
|
||||
if downloader == "grab" {
|
||||
return http.NewGrabDownloader(downloadLimit*1024, maxTries, progress)
|
||||
}
|
||||
return http.NewDownloader(downloadLimit*1024, maxTries, progress)
|
||||
}
|
||||
|
||||
// Downloader returns instance of current downloader
|
||||
func (context *AptlyContext) Downloader() aptly.Downloader {
|
||||
context.Lock()
|
||||
defer context.Unlock()
|
||||
|
||||
if context.downloader == nil {
|
||||
var downloadLimit int64
|
||||
limitFlag := context.flags.Lookup("download-limit")
|
||||
if limitFlag != nil {
|
||||
downloadLimit = limitFlag.Value.Get().(int64)
|
||||
}
|
||||
if downloadLimit == 0 {
|
||||
downloadLimit = context.config().DownloadLimit
|
||||
}
|
||||
context.downloader = http.NewDownloader(downloadLimit*1024, context._progress())
|
||||
context.downloader = context.newDownloader(context._progress())
|
||||
}
|
||||
|
||||
return context.downloader
|
||||
}
|
||||
|
||||
// TaskList returns instance of current task list
|
||||
func (context *AptlyContext) TaskList() *task.List {
|
||||
context.Lock()
|
||||
defer context.Unlock()
|
||||
|
||||
if context.taskList == nil {
|
||||
context.taskList = task.NewList()
|
||||
}
|
||||
return context.taskList
|
||||
}
|
||||
|
||||
// DBPath builds path to database
|
||||
func (context *AptlyContext) DBPath() string {
|
||||
context.Lock()
|
||||
@@ -244,13 +287,19 @@ func (context *AptlyContext) _database() (database.Storage, error) {
|
||||
if context.database == nil {
|
||||
var err error
|
||||
|
||||
context.database, err = database.NewDB(context.dbPath())
|
||||
context.database, err = goleveldb.NewDB(context.dbPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't instantiate database: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
tries := context.flags.Lookup("db-open-attempts").Value.Get().(int)
|
||||
var tries int
|
||||
if context.config().DatabaseOpenAttempts == -1 {
|
||||
tries = context.flags.Lookup("db-open-attempts").Value.Get().(int)
|
||||
} else {
|
||||
tries = context.config().DatabaseOpenAttempts
|
||||
}
|
||||
|
||||
const BaseDelay = 10 * time.Second
|
||||
const Jitter = 1 * time.Second
|
||||
|
||||
@@ -293,20 +342,16 @@ func (context *AptlyContext) ReOpenDatabase() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// CollectionFactory builds factory producing all kinds of collections
|
||||
func (context *AptlyContext) CollectionFactory() *deb.CollectionFactory {
|
||||
// NewCollectionFactory builds factory producing all kinds of collections
|
||||
func (context *AptlyContext) NewCollectionFactory() *deb.CollectionFactory {
|
||||
context.Lock()
|
||||
defer context.Unlock()
|
||||
|
||||
if context.collectionFactory == nil {
|
||||
db, err := context._database()
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
context.collectionFactory = deb.NewCollectionFactory(db)
|
||||
db, err := context._database()
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
return context.collectionFactory
|
||||
return deb.NewCollectionFactory(db)
|
||||
}
|
||||
|
||||
// PackagePool returns instance of PackagePool
|
||||
@@ -364,6 +409,18 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
} else if strings.HasPrefix(name, "azure:") {
|
||||
params, ok := context.config().AzurePublishRoots[name[6:]]
|
||||
if !ok {
|
||||
Fatal(fmt.Errorf("Published Azure storage %v not configured", name[6:]))
|
||||
}
|
||||
|
||||
var err error
|
||||
publishedStorage, err = azure.NewPublishedStorage(
|
||||
params.AccountName, params.AccountKey, params.Container, params.Prefix, params.Endpoint)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
} else {
|
||||
Fatal(fmt.Errorf("unknown published storage format: %v", name))
|
||||
}
|
||||
@@ -468,7 +525,7 @@ func (context *AptlyContext) GoContextHandleSignals() {
|
||||
defer context.Unlock()
|
||||
|
||||
// Catch ^C
|
||||
sigch := make(chan os.Signal)
|
||||
sigch := make(chan os.Signal, 1)
|
||||
signal.Notify(sigch, os.Interrupt)
|
||||
|
||||
var cancel gocontext.CancelFunc
|
||||
|
||||
Reference in New Issue
Block a user