mirror of
https://github.com/kopia/kopia.git
synced 2026-10-22 14:15:03 -04:00
changed object.ManagerOptions into a struct
This commit is contained in:
1 parent
59bb3ef943
commit
a45f557c4b
5 files changed
+24
-26
No files matched your search
@@ -41,7 +41,9 @@ var (
|
||||
|
||||
func runBackupCommand(c *kingpin.ParseContext) error {
|
||||
rep := mustOpenRepository(&repo.Options{
|
||||
ObjectManagerOptions: []object.ManagerOption{object.WriteBack(*snapshotCreateWriteBack)},
|
||||
ObjectManagerOptions: object.ManagerOptions{
|
||||
WriteBack: *snapshotCreateWriteBack,
|
||||
},
|
||||
})
|
||||
defer rep.Close()
|
||||
|
||||
|
||||
+1
-3
@@ -12,8 +12,6 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/kopia/kopia/object"
|
||||
|
||||
"github.com/bgentry/speakeasy"
|
||||
"github.com/kopia/kopia/auth"
|
||||
"github.com/kopia/kopia/fs"
|
||||
@@ -81,7 +79,7 @@ func applyOptionsFromFlags(opts *repo.Options) *repo.Options {
|
||||
}
|
||||
|
||||
if *traceObjectManager {
|
||||
opts.ObjectManagerOptions = append(opts.ObjectManagerOptions, object.Trace(log.Printf))
|
||||
opts.ObjectManagerOptions.Trace = log.Printf
|
||||
}
|
||||
|
||||
return opts
|
||||
|
||||
+14
-16
@@ -186,23 +186,14 @@ func validateFormat(f *config.RepositoryObjectFormat) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ManagerOption func(om *Manager)
|
||||
|
||||
func WriteBack(parallelism int) ManagerOption {
|
||||
return func(om *Manager) {
|
||||
om.async = true
|
||||
om.writeBackSemaphore = make(semaphore, parallelism)
|
||||
}
|
||||
}
|
||||
|
||||
func Trace(traceFunc func(message string, args ...interface{})) ManagerOption {
|
||||
return func(om *Manager) {
|
||||
om.trace = traceFunc
|
||||
}
|
||||
// ManagerOptions specifies object manager options.
|
||||
type ManagerOptions struct {
|
||||
WriteBack int
|
||||
Trace func(message string, args ...interface{})
|
||||
}
|
||||
|
||||
// NewObjectManager creates an ObjectManager with the specified block manager and format.
|
||||
func NewObjectManager(bm blockManager, f config.RepositoryObjectFormat, opts ...ManagerOption) (*Manager, error) {
|
||||
func NewObjectManager(bm blockManager, f config.RepositoryObjectFormat, opts ManagerOptions) (*Manager, error) {
|
||||
if err := validateFormat(&f); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -227,8 +218,15 @@ func NewObjectManager(bm blockManager, f config.RepositoryObjectFormat, opts ...
|
||||
return os(&f)
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(om)
|
||||
if opts.Trace != nil {
|
||||
om.trace = opts.Trace
|
||||
} else {
|
||||
om.trace = nullTrace
|
||||
}
|
||||
|
||||
if opts.WriteBack > 0 {
|
||||
om.async = true
|
||||
om.writeBackSemaphore = make(semaphore, opts.WriteBack)
|
||||
}
|
||||
|
||||
return om, nil
|
||||
|
||||
@@ -63,16 +63,16 @@ func (f *fakeBlockManager) Flush() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func setupTest(t *testing.T, mods ...func(o *ManagerOption)) (map[string][]byte, *Manager) {
|
||||
return setupTestWithData(t, map[string][]byte{}, mods...)
|
||||
func setupTest(t *testing.T) (map[string][]byte, *Manager) {
|
||||
return setupTestWithData(t, map[string][]byte{}, ManagerOptions{})
|
||||
}
|
||||
|
||||
func setupTestWithData(t *testing.T, data map[string][]byte, mods ...func(o *ManagerOption)) (map[string][]byte, *Manager) {
|
||||
func setupTestWithData(t *testing.T, data map[string][]byte, opts ManagerOptions) (map[string][]byte, *Manager) {
|
||||
r, err := NewObjectManager(&fakeBlockManager{data: data}, config.RepositoryObjectFormat{
|
||||
Version: 1,
|
||||
MaxBlockSize: 200,
|
||||
Splitter: "FIXED",
|
||||
})
|
||||
}, opts)
|
||||
if err != nil {
|
||||
t.Fatalf("can't create object manager: %v", err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ type Options struct {
|
||||
CredentialsCallback func() (auth.Credentials, error) // Provides credentials required to open the repository if not persisted.
|
||||
TraceStorage func(f string, args ...interface{}) // Logs all storage access using provided Printf-style function
|
||||
|
||||
ObjectManagerOptions []object.ManagerOption
|
||||
ObjectManagerOptions object.ManagerOptions
|
||||
}
|
||||
|
||||
// Open opens a Repository specified in the configuration file.
|
||||
@@ -139,7 +139,7 @@ func connect(ctx context.Context, st storage.Storage, creds auth.Credentials, op
|
||||
|
||||
bm := block.NewManager(st, mm.repoConfig.Format.MaxPackedContentLength, mm.repoConfig.Format.MaxBlockSize, formatter)
|
||||
|
||||
om, err := object.NewObjectManager(bm, mm.repoConfig.Format, options.ObjectManagerOptions...)
|
||||
om, err := object.NewObjectManager(bm, mm.repoConfig.Format, options.ObjectManagerOptions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to open object manager: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user