diff --git a/cli/command_ls.go b/cli/command_ls.go index 6efade8a0..2887e1cb3 100644 --- a/cli/command_ls.go +++ b/cli/command_ls.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/kopia/kopia/fs" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/object" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/snapshot" @@ -48,7 +49,7 @@ func init() { } func listDirectory(ctx context.Context, mgr *snapshot.Manager, prefix string, oid object.ID, indent string) error { - d := mgr.DirectoryEntry(oid, nil) + d := repofs.DirectoryEntry(mgr, oid, nil) entries, err := d.Readdir(ctx) if err != nil { diff --git a/cli/command_mount.go b/cli/command_mount.go index 0d458d390..264cb6e38 100644 --- a/cli/command_mount.go +++ b/cli/command_mount.go @@ -7,6 +7,7 @@ import ( "github.com/kopia/kopia/fs" "github.com/kopia/kopia/fs/cachefs" "github.com/kopia/kopia/fs/loggingfs" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/snapshot" ) @@ -24,13 +25,13 @@ func runMountCommand(ctx context.Context, rep *repo.Repository) error { var entry fs.Directory if *mountObjectID == "all" { - entry = mgr.AllSourcesEntry() + entry = repofs.AllSourcesEntry(mgr) } else { oid, err := parseObjectID(ctx, mgr, *mountObjectID) if err != nil { return err } - entry = mgr.DirectoryEntry(oid, nil) + entry = repofs.DirectoryEntry(mgr, oid, nil) } if *mountTraceFS { diff --git a/cli/command_object_verify.go b/cli/command_object_verify.go index d0139dee2..5ee426d4d 100644 --- a/cli/command_object_verify.go +++ b/cli/command_object_verify.go @@ -11,6 +11,7 @@ import ( "github.com/kopia/kopia/block" "github.com/kopia/kopia/fs" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/internal/parallelwork" "github.com/kopia/kopia/object" "github.com/kopia/kopia/repo" @@ -111,7 +112,7 @@ func (v *verifier) enqueueVerifyObject(ctx context.Context, oid object.ID, path func (v *verifier) doVerifyDirectory(ctx context.Context, oid object.ID, path string) { log.Debugf("verifying directory %q (%v)", path, oid) - d := v.mgr.DirectoryEntry(oid, nil) + d := repofs.DirectoryEntry(v.mgr, oid, nil) entries, err := d.Readdir(ctx) if err != nil { v.reportError(path, fmt.Errorf("error reading %v: %v", oid, err)) diff --git a/cli/command_repository_migrate.go b/cli/command_repository_migrate.go index 51ec1859d..7fab14096 100644 --- a/cli/command_repository_migrate.go +++ b/cli/command_repository_migrate.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/object" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/snapshot" @@ -54,7 +55,7 @@ func runMigrateCommand(ctx context.Context, destRepo *repo.Repository) error { if err != nil { return err } - d := sourceSM.DirectoryEntry(dirOID, nil) + d := repofs.DirectoryEntry(sourceSM, dirOID, nil) newm, err := uploader.Upload(ctx, d, snapshot.SourceInfo{Host: "temp"}, nil) if err != nil { return fmt.Errorf("error migrating directory %v: %v", dirOID, err) @@ -76,7 +77,7 @@ func migrateSingleSource(ctx context.Context, uploader *snapshot.Uploader, sourc } for _, m := range filterSnapshotsToMigrate(snapshots) { - d := sourceSM.DirectoryEntry(m.RootObjectID(), nil) + d := repofs.DirectoryEntry(sourceSM, m.RootObjectID(), nil) newm, err := uploader.Upload(ctx, d, m.Source, nil) if err != nil { return fmt.Errorf("error migrating shapshot %v @ %v: %v", m.Source, m.StartTime, err) diff --git a/cli/command_snapshot_list.go b/cli/command_snapshot_list.go index 27dad3cbe..0e0bdb5ee 100644 --- a/cli/command_snapshot_list.go +++ b/cli/command_snapshot_list.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/kopia/kopia/fs" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/internal/units" "github.com/kopia/kopia/object" "github.com/kopia/kopia/repo" @@ -121,7 +122,7 @@ func outputManifestFromSingleSource(ctx context.Context, manifests []*snapshot.M } for _, m := range manifests { - root, err := mgr.SnapshotRoot(m) + root, err := repofs.SnapshotRoot(mgr, m) if err != nil { fmt.Printf(" %v %v\n", m.StartTime.Format("2006-01-02 15:04:05 MST"), err) continue diff --git a/cli/objref.go b/cli/objref.go index 737a0acf4..81312eca9 100644 --- a/cli/objref.go +++ b/cli/objref.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/kopia/kopia/fs" + "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/object" "github.com/kopia/kopia/snapshot" ) @@ -22,7 +23,7 @@ func parseObjectID(ctx context.Context, mgr *snapshot.Manager, id string) (objec return oid, nil } - dir := mgr.DirectoryEntry(oid, nil) + dir := repofs.DirectoryEntry(mgr, oid, nil) return parseNestedObjectID(ctx, dir, parts[1:]) } diff --git a/snapshot/all_sources.go b/fs/repofs/all_sources.go similarity index 78% rename from snapshot/all_sources.go rename to fs/repofs/all_sources.go index 6a7e37452..f32f1e45b 100644 --- a/snapshot/all_sources.go +++ b/fs/repofs/all_sources.go @@ -1,4 +1,4 @@ -package snapshot +package repofs import ( "context" @@ -6,12 +6,11 @@ import ( "time" "github.com/kopia/kopia/fs" - "github.com/kopia/kopia/repo" + "github.com/kopia/kopia/snapshot" ) type repositoryAllSources struct { - repo *repo.Repository - snapshotManager *Manager + snapshotManager *snapshot.Manager } func (s *repositoryAllSources) Summary() *fs.DirectorySummary { @@ -38,7 +37,6 @@ func (s *repositoryAllSources) Readdir(ctx context.Context) (fs.Entries, error) var result fs.Entries for u := range users { result = append(result, &sourceDirectories{ - repo: s.repo, snapshotManager: s.snapshotManager, userHost: u, }) @@ -49,6 +47,6 @@ func (s *repositoryAllSources) Readdir(ctx context.Context) (fs.Entries, error) } // 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} +func AllSourcesEntry(m *snapshot.Manager) fs.Directory { + return &repositoryAllSources{snapshotManager: m} } diff --git a/snapshot/repofs.go b/fs/repofs/repofs.go similarity index 88% rename from snapshot/repofs.go rename to fs/repofs/repofs.go index 0f933641b..97a18cd31 100644 --- a/snapshot/repofs.go +++ b/fs/repofs/repofs.go @@ -1,10 +1,13 @@ -package snapshot +// Package repofs implements virtual filesystem on top of snapshots in repo.Repository. +package repofs import ( "context" "fmt" "io/ioutil" + "github.com/kopia/kopia/snapshot" + "github.com/kopia/kopia/fs" "github.com/kopia/kopia/internal/dir" "github.com/kopia/kopia/object" @@ -128,8 +131,8 @@ func withMetadata(r object.Reader, md *fs.EntryMetadata) fs.Reader { // 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 (m *Manager) DirectoryEntry(objectID object.ID, dirSummary *fs.DirectorySummary) fs.Directory { - d := newRepoEntry(m.repository, &dir.Entry{ +func DirectoryEntry(m *snapshot.Manager, objectID object.ID, dirSummary *fs.DirectorySummary) fs.Directory { + d := newRepoEntry(m.Repository, &dir.Entry{ EntryMetadata: fs.EntryMetadata{ Name: "/", Permissions: 0555, @@ -143,13 +146,13 @@ func (m *Manager) DirectoryEntry(objectID object.ID, dirSummary *fs.DirectorySum } // SnapshotRoot returns fs.Entry representing the root of a snapshot. -func (m *Manager) SnapshotRoot(man *Manifest) (fs.Entry, error) { +func SnapshotRoot(m *snapshot.Manager, man *snapshot.Manifest) (fs.Entry, error) { oid := man.RootObjectID() if oid == "" { return nil, fmt.Errorf("manifest root object ID") } - return newRepoEntry(m.repository, man.RootEntry), nil + return newRepoEntry(m.Repository, man.RootEntry), nil } var _ fs.Directory = &repositoryDirectory{} diff --git a/snapshot/source_directories.go b/fs/repofs/source_directories.go similarity index 78% rename from snapshot/source_directories.go rename to fs/repofs/source_directories.go index ad8fd74ae..0efb120c4 100644 --- a/snapshot/source_directories.go +++ b/fs/repofs/source_directories.go @@ -1,16 +1,15 @@ -package snapshot +package repofs import ( "context" "time" "github.com/kopia/kopia/fs" - "github.com/kopia/kopia/repo" + "github.com/kopia/kopia/snapshot" ) type sourceDirectories struct { - repo *repo.Repository - snapshotManager *Manager + snapshotManager *snapshot.Manager userHost string } @@ -36,7 +35,7 @@ func (s *sourceDirectories) Readdir(ctx context.Context) (fs.Entries, error) { continue } - result = append(result, &sourceSnapshots{s.repo, s.snapshotManager, src}) + result = append(result, &sourceSnapshots{s.snapshotManager, src}) } result.Sort() diff --git a/snapshot/source_snapshots.go b/fs/repofs/source_snapshots.go similarity index 87% rename from snapshot/source_snapshots.go rename to fs/repofs/source_snapshots.go index dbb9e8052..85563e23a 100644 --- a/snapshot/source_snapshots.go +++ b/fs/repofs/source_snapshots.go @@ -1,4 +1,4 @@ -package snapshot +package repofs import ( "context" @@ -7,13 +7,12 @@ import ( "github.com/kopia/kopia/fs" "github.com/kopia/kopia/internal/dir" - "github.com/kopia/kopia/repo" + "github.com/kopia/kopia/snapshot" ) type sourceSnapshots struct { - repo *repo.Repository - snapshotManager *Manager - src SourceInfo + snapshotManager *snapshot.Manager + src snapshot.SourceInfo } func (s *sourceSnapshots) Metadata() *fs.EntryMetadata { @@ -61,7 +60,7 @@ func (s *sourceSnapshots) Readdir(ctx context.Context) (fs.Entries, error) { de.DirSummary = m.RootEntry.DirSummary } - e := newRepoEntry(s.repo, de) + e := newRepoEntry(s.snapshotManager.Repository, de) result = append(result, e) } diff --git a/snapshot/manager.go b/snapshot/manager.go index 77bf30253..4846ef977 100644 --- a/snapshot/manager.go +++ b/snapshot/manager.go @@ -13,12 +13,12 @@ var GlobalPolicySourceInfo = SourceInfo{} // Manager manages filesystem snapshots. type Manager struct { - repository *repo.Repository + Repository *repo.Repository } // ListSources lists all snapshot sources. func (m *Manager) ListSources() []SourceInfo { - items := m.repository.Manifests.Find(map[string]string{ + items := m.Repository.Manifests.Find(map[string]string{ "type": "snapshot", }) @@ -50,13 +50,13 @@ func sourceInfoToLabels(si SourceInfo) map[string]string { // ListSnapshots lists all snapshots for a given source. func (m *Manager) ListSnapshots(si SourceInfo) ([]*Manifest, error) { - return m.LoadSnapshots(manifest.EntryIDs(m.repository.Manifests.Find(sourceInfoToLabels(si)))) + return m.LoadSnapshots(manifest.EntryIDs(m.Repository.Manifests.Find(sourceInfoToLabels(si)))) } // LoadSnapshot loads and parses a snapshot with a given ID. func (m *Manager) LoadSnapshot(manifestID string) (*Manifest, error) { sm := &Manifest{} - if err := m.repository.Manifests.Get(manifestID, sm); err != nil { + if err := m.Repository.Manifests.Get(manifestID, sm); err != nil { return nil, err } @@ -67,7 +67,7 @@ func (m *Manager) LoadSnapshot(manifestID string) (*Manifest, error) { // SaveSnapshot persists given snapshot manifest and returns manifest ID. func (m *Manager) SaveSnapshot(manifest *Manifest) (string, error) { - return m.repository.Manifests.Put(sourceInfoToLabels(manifest.Source), manifest) + return m.Repository.Manifests.Put(sourceInfoToLabels(manifest.Source), manifest) } // LoadSnapshots efficiently loads and parses a given list of snapshot IDs. @@ -114,7 +114,7 @@ func (m *Manager) ListSnapshotManifests(src *SourceInfo) []string { labels = sourceInfoToLabels(*src) } - return manifest.EntryIDs(m.repository.Manifests.Find(labels)) + return manifest.EntryIDs(m.Repository.Manifests.Find(labels)) } // NewManager creates new snapshot manager for a given connection.