replaced use of Vault with Repository

This commit is contained in:
Jarek Kowalski
2017-07-18 13:39:26 +02:00
parent 50c2cd86a3
commit 4dcdb69dcc
21 changed files with 54 additions and 99 deletions

View File

@@ -50,7 +50,7 @@ func runBackupCommand(c *kingpin.ParseContext) error {
defer conn.Close()
ctx := context.Background()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
sources := *backupSources
if *backupAll {
@@ -66,7 +66,7 @@ func runBackupCommand(c *kingpin.ParseContext) error {
}
for _, backupDirectory := range sources {
conn.Repository.Stats.Reset()
conn.Stats.Reset()
log.Printf("Backing up %v", backupDirectory)
dir, err := filepath.Abs(backupDirectory)
if err != nil {
@@ -101,7 +101,7 @@ func runBackupCommand(c *kingpin.ParseContext) error {
manifest, err := snapshot.Upload(
ctx,
conn.Repository,
conn,
localEntry,
sourceInfo,
policy.Files,

View File

@@ -52,7 +52,7 @@ func runBackupsCommand(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
defer conn.Close()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
var previous []string
var relPath string

View File

@@ -16,11 +16,11 @@ func runCatCommand(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
defer conn.Close()
oid, err := parseObjectID(*catCommandPath, conn.Vault, conn.Repository)
oid, err := parseObjectID(*catCommandPath, conn)
if err != nil {
return err
}
r, err := conn.Repository.Open(oid)
r, err := conn.Open(oid)
if err != nil {
return err
}

View File

@@ -152,7 +152,7 @@ func runCleanupCommand(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
defer conn.Close()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
log.Printf("Listing active snapshots...")
snapshotNames, err := mgr.ListSnapshotManifests(nil, -1)
@@ -167,7 +167,7 @@ func runCleanupCommand(context *kingpin.ParseContext) error {
}
ctx := &cleanupContext{
repo: conn.Repository,
repo: conn,
inuse: map[string]bool{},
visited: map[string]bool{},
queue: q,
@@ -248,7 +248,7 @@ func runCleanupCommand(context *kingpin.ParseContext) error {
var unreferencedBlocks int
var unreferencedBytes int64
blocks, cancel := conn.Repository.Storage.ListBlocks("")
blocks, cancel := conn.Storage.ListBlocks("")
defer cancel()
for b := range blocks {
totalBlocks++

View File

@@ -181,7 +181,7 @@ func runExpireCommand(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
defer conn.Close()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
snapshotNames, err := getSnapshotNamesToExpire(mgr)
if err != nil {
return err

View File

@@ -5,7 +5,6 @@
"strconv"
"strings"
"github.com/kopia/kopia/client"
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/fs/repofs"
"github.com/kopia/kopia/repo"
@@ -26,7 +25,7 @@ func runLSCommand(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
defer conn.Close()
oid, err := parseObjectID(*lsCommandPath, conn.Vault, conn.Repository)
oid, err := parseObjectID(*lsCommandPath, conn)
if err != nil {
return err
}
@@ -46,8 +45,8 @@ func init() {
lsCommand.Action(runLSCommand)
}
func listDirectory(conn *client.Connection, prefix string, oid repo.ObjectID, indent string) error {
d := repofs.Directory(conn.Repository, oid)
func listDirectory(conn *repo.Repository, prefix string, oid repo.ObjectID, indent string) error {
d := repofs.Directory(conn, oid)
entries, err := d.Readdir()
if err != nil {

View File

@@ -43,12 +43,12 @@ func runMountCommand(context *kingpin.ParseContext) error {
fuse.VolumeName("Kopia"),
)
oid, err := parseObjectID(*mountObjectID, conn.Vault, conn.Repository)
oid, err := parseObjectID(*mountObjectID, conn)
if err != nil {
return err
}
entry := repofs.Directory(conn.Repository, oid)
entry := repofs.Directory(conn, oid)
if *mountTraceFS {
entry = loggingfs.Wrap(entry).(fs.Directory)
}

View File

@@ -17,7 +17,7 @@ func init() {
func listPolicies(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
policies, err := mgr.ListPolicies()
if err != nil {

View File

@@ -19,7 +19,7 @@ func init() {
func removePolicy(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
targets, err := policyTargets(policyRemoveGlobal, policyRemoveTargets)
if err != nil {

View File

@@ -37,7 +37,7 @@ func init() {
func setPolicy(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
_ = mgr
targets, err := policyTargets(policySetGlobal, policySetTargets)

View File

@@ -20,7 +20,7 @@ func init() {
func showPolicy(context *kingpin.ParseContext) error {
conn := mustOpenConnection()
mgr := snapshot.NewManager(conn.Vault)
mgr := snapshot.NewManager(conn)
targets, err := policyTargets(policyShowGlobal, policyShowTargets)
if err != nil {

View File

@@ -24,12 +24,12 @@ func runShowCommand(context *kingpin.ParseContext) error {
defer conn.Close()
for _, oidString := range *showObjectIDs {
oid, err := parseObjectID(oidString, conn.Vault, conn.Repository)
oid, err := parseObjectID(oidString, conn)
if err != nil {
return err
}
if err := showObject(conn.Repository, oid); err != nil {
if err := showObject(conn, oid); err != nil {
return err
}
}

View File

@@ -50,7 +50,7 @@ func getContext() context.Context {
return ctx
}
func openConnection(options ...repo.RepositoryOption) (*client.Connection, error) {
func openConnection(options ...repo.RepositoryOption) (*repo.Repository, error) {
return client.Open(getContext(), vaultConfigFileName(), connectionOptionsFromFlags(options...))
}
@@ -75,7 +75,7 @@ func connectionOptionsFromFlags(options ...repo.RepositoryOption) *client.Option
return opts
}
func mustOpenConnection(repoOptions ...repo.RepositoryOption) *client.Connection {
func mustOpenConnection(repoOptions ...repo.RepositoryOption) *repo.Repository {
s, err := openConnection(repoOptions...)
failOnError(err)
return s
@@ -113,8 +113,8 @@ func vaultConfigFileName() string {
return filepath.Join(getHomeDir(), ".kopia/vault.config")
}
func persistVaultConfig(v *repo.Vault) error {
cfg, err := v.Config()
func persistVaultConfig(r *repo.Vault) error {
cfg, err := r.Config()
if err != nil {
return err
}

View File

@@ -10,7 +10,7 @@
)
// ParseObjectID interprets the given ID string and returns corresponding repo.ObjectID.
func parseObjectID(id string, vlt *repo.Vault, r *repo.Repository) (repo.ObjectID, error) {
func parseObjectID(id string, r *repo.Repository) (repo.ObjectID, error) {
head, tail := splitHeadTail(id)
if len(head) == 0 {
return repo.NullObjectID, fmt.Errorf("invalid object ID: %v", id)