mirror of
https://github.com/kopia/kopia.git
synced 2026-10-25 07:38:50 -04:00
moved repository VFS nodes into fs/repofs/ package
This commit is contained in:
1 parent
0f20965143
commit
9060e7d310
11 files changed
+42
-37
No files matched your search
+2
-1
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 <ERROR> %v\n", m.StartTime.Format("2006-01-02 15:04:05 MST"), err)
|
||||
continue
|
||||
|
||||
+2
-1
@@ -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:])
|
||||
}
|
||||
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
@@ -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{}
|
||||
@@ -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()
|
||||
@@ -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)
|
||||
}
|
||||
+6
-6
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user