moved creation of repofs entries to snapshot.Manager

This commit is contained in:
Jarek Kowalski
2017-09-04 20:47:51 -07:00
parent 371fc15694
commit 76b712c2fb
9 changed files with 35 additions and 23 deletions

View File

@@ -4,6 +4,8 @@
"io"
"os"
"github.com/kopia/kopia/snapshot"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
@@ -16,7 +18,9 @@ func runCatCommand(context *kingpin.ParseContext) error {
rep := mustOpenRepository(nil)
defer rep.Close()
oid, err := parseObjectID(*catCommandPath, rep)
mgr := snapshot.NewManager(rep)
oid, err := parseObjectID(mgr, *catCommandPath)
if err != nil {
return err
}

View File

@@ -25,7 +25,9 @@ func runLSCommand(context *kingpin.ParseContext) error {
rep := mustOpenRepository(nil)
defer rep.Close()
oid, err := parseObjectID(*lsCommandPath, rep)
mgr := snapshot.NewManager(rep)
oid, err := parseObjectID(mgr, *lsCommandPath)
if err != nil {
return err
}
@@ -38,15 +40,15 @@ func runLSCommand(context *kingpin.ParseContext) error {
}
}
return listDirectory(rep, prefix, oid, "")
return listDirectory(mgr, prefix, oid, "")
}
func init() {
lsCommand.Action(runLSCommand)
}
func listDirectory(rep *repo.Repository, prefix string, oid repo.ObjectID, indent string) error {
d := snapshot.Directory(rep, oid)
func listDirectory(mgr *snapshot.Manager, prefix string, oid repo.ObjectID, indent string) error {
d := mgr.DirectoryEntry(oid)
entries, err := d.Readdir()
if err != nil {
@@ -93,7 +95,7 @@ func listDirectory(rep *repo.Repository, prefix string, oid repo.ObjectID, inden
}
fmt.Println(info)
if *lsCommandRecursive && m.FileMode().IsDir() {
listDirectory(rep, prefix+m.Name+"/", objectID, indent+" ")
listDirectory(mgr, prefix+m.Name+"/", objectID, indent+" ")
}
}

View File

@@ -23,6 +23,8 @@
func runMountCommand(context *kingpin.ParseContext) error {
rep := mustOpenRepository(nil)
mgr := snapshot.NewManager(rep)
var entry fs.Directory
if *mountCacheRefreshInterval > 0 {
@@ -38,13 +40,13 @@ func runMountCommand(context *kingpin.ParseContext) error {
}
if *mountObjectID == "all" {
entry = snapshot.AllSources(rep)
entry = mgr.AllSourcesEntry()
} else {
oid, err := parseObjectID(*mountObjectID, rep)
oid, err := parseObjectID(mgr, *mountObjectID)
if err != nil {
return err
}
entry = snapshot.Directory(rep, oid)
entry = mgr.DirectoryEntry(oid)
}
if *mountTraceFS {

View File

@@ -112,6 +112,7 @@ type cleanupContext struct {
sync.Mutex
repo *repo.Repository
mgr *snapshot.Manager
inuse map[string]bool
visited map[string]bool
queue *cleanupWorkQueue
@@ -130,7 +131,7 @@ func findAliveBlocks(ctx *cleanupContext, wi *cleanupWorkItem) error {
}
if wi.isDirectory {
entries, err := snapshot.Directory(ctx.repo, wi.oid).Readdir()
entries, err := ctx.mgr.DirectoryEntry(wi.oid).Readdir()
if err != nil {
return err
@@ -167,6 +168,7 @@ func runCleanupCommand(context *kingpin.ParseContext) error {
ctx := &cleanupContext{
repo: rep,
mgr: mgr,
inuse: map[string]bool{},
visited: map[string]bool{},
queue: q,

View File

@@ -6,6 +6,8 @@
"io/ioutil"
"os"
"github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/repo"
kingpin "gopkg.in/alecthomas/kingpin.v2"
@@ -23,8 +25,10 @@ func runShowCommand(context *kingpin.ParseContext) error {
rep := mustOpenRepository(nil)
defer rep.Close()
mgr := snapshot.NewManager(rep)
for _, oidString := range *showObjectIDs {
oid, err := parseObjectID(oidString, rep)
oid, err := parseObjectID(mgr, oidString)
if err != nil {
return err
}

View File

@@ -58,7 +58,7 @@ func runMigrateCommand(context *kingpin.ParseContext) error {
}
for _, m := range filterSnapshotsToMigrate(snapshots) {
d := snapshot.Directory(sourceRepo, m.RootObjectID)
d := sourceSM.DirectoryEntry(m.RootObjectID)
newm, err := uploader.Upload(d, &m.Source, nil)
if err != nil {
return fmt.Errorf("error migrating shapshot %v @ %v: %v", m.Source, m.StartTime, err)
@@ -80,7 +80,7 @@ func runMigrateCommand(context *kingpin.ParseContext) error {
if err != nil {
return err
}
d := snapshot.Directory(sourceRepo, dirOID)
d := sourceSM.DirectoryEntry(dirOID)
newm, err := uploader.Upload(d, &snapshot.SourceInfo{Host: "temp"}, nil)
if err != nil {
return fmt.Errorf("error migrating directory %v: %v", dirOID, err)

View File

@@ -10,7 +10,7 @@
)
// ParseObjectID interprets the given ID string and returns corresponding repo.ObjectID.
func parseObjectID(id string, r *repo.Repository) (repo.ObjectID, error) {
func parseObjectID(mgr *snapshot.Manager, id string) (repo.ObjectID, error) {
head, tail := splitHeadTail(id)
if len(head) == 0 {
return repo.NullObjectID, fmt.Errorf("invalid object ID: %v", id)
@@ -25,7 +25,7 @@ func parseObjectID(id string, r *repo.Repository) (repo.ObjectID, error) {
return oid, nil
}
dir := snapshot.Directory(r, oid)
dir := mgr.DirectoryEntry(oid)
if err != nil {
return repo.NullObjectID, err
}

View File

@@ -51,9 +51,7 @@ func (s *repositoryAllSources) Readdir() (fs.Entries, error) {
return result, nil
}
// AllSources returns fs.Directory that contains the list of all snapshot sources found in the repository.
func AllSources(r *repo.Repository) fs.Directory {
sm := NewManager(r)
return &repositoryAllSources{repo: r, snapshotManager: sm}
// AllSourcesEntry returns fs.Directory that contains the list of all snapshot sources found in the repository.
func (m *Manager) AllSourcesEntry() fs.Directory {
return &repositoryAllSources{repo: m.repository, snapshotManager: m}
}

View File

@@ -117,10 +117,10 @@ func withMetadata(r repo.ObjectReader, md *fs.EntryMetadata) fs.Reader {
return &entryMetadataReadCloser{r, md}
}
// Directory returns fs.Directory based on repository object with the specified ID.
// DirectoryEntry returns fs.Directory based on repository object with the specified ID.
// The existence or validity of the directory object is not validated until its contents are read.
func Directory(r *repo.Repository, objectID repo.ObjectID) fs.Directory {
d := newRepoEntry(r, &dir.Entry{
func (m *Manager) DirectoryEntry(objectID repo.ObjectID) fs.Directory {
d := newRepoEntry(m.repository, &dir.Entry{
EntryMetadata: fs.EntryMetadata{
Name: "/",
Permissions: 0555,