From 81fd499bae1fc79be9feedf22a0ab416790ee2b3 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Mon, 30 Jan 2017 20:07:02 -0800 Subject: [PATCH] moved upload functionality to snapshot package --- cmd/kopia/command_backup.go | 3 +-- cmd/kopia/progress.go | 4 ++-- {fs/repofs => snapshot}/upload.go | 15 +++++++-------- {fs/repofs => snapshot}/upload_progress.go | 2 +- {fs/repofs => snapshot}/upload_test.go | 17 ++++++++--------- 5 files changed, 19 insertions(+), 22 deletions(-) rename {fs/repofs => snapshot}/upload.go (98%) rename {fs/repofs => snapshot}/upload_progress.go (97%) rename {fs/repofs => snapshot}/upload_test.go (90%) diff --git a/cmd/kopia/command_backup.go b/cmd/kopia/command_backup.go index 320022184..521180abd 100644 --- a/cmd/kopia/command_backup.go +++ b/cmd/kopia/command_backup.go @@ -16,7 +16,6 @@ "runtime" "strings" - "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/snapshot" @@ -97,7 +96,7 @@ func runBackupCommand(c *kingpin.ParseContext) error { return err } - manifest, err := repofs.Upload( + manifest, err := snapshot.Upload( ctx, conn.Repository, localEntry, diff --git a/cmd/kopia/progress.go b/cmd/kopia/progress.go index bcaf25a0c..e4747e5f1 100644 --- a/cmd/kopia/progress.go +++ b/cmd/kopia/progress.go @@ -6,8 +6,8 @@ "time" "github.com/cheggaaa/pb" - "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/internal/units" + "github.com/kopia/kopia/snapshot" ) type uploadProgress struct { @@ -55,4 +55,4 @@ func (p *uploadProgress) Progress(path string, completed, total int64) { p.bar.Set64(completed) } -var up repofs.UploadProgress = &uploadProgress{} +var up snapshot.UploadProgress = &uploadProgress{} diff --git a/fs/repofs/upload.go b/snapshot/upload.go similarity index 98% rename from fs/repofs/upload.go rename to snapshot/upload.go index 17dca082d..b8afd0d1f 100644 --- a/fs/repofs/upload.go +++ b/snapshot/upload.go @@ -1,4 +1,4 @@ -package repofs +package snapshot import ( "context" @@ -12,7 +12,6 @@ "github.com/kopia/kopia/internal/dir" "github.com/kopia/kopia/internal/hashcache" "github.com/kopia/kopia/repo" - "github.com/kopia/kopia/snapshot" ) const ( @@ -55,7 +54,7 @@ type uploadContext struct { cacheWriter *hashcache.Writer cacheReader *hashcache.Reader - stats *snapshot.Stats + stats *Stats progress UploadProgress uploadBuf []byte @@ -524,10 +523,10 @@ func Upload( ctx context.Context, repository *repo.Repository, source fs.Entry, - sourceInfo *snapshot.SourceInfo, - old *snapshot.Manifest, + sourceInfo *SourceInfo, + old *Manifest, progress UploadProgress, -) (*snapshot.Manifest, error) { +) (*Manifest, error) { if progress == nil { progress = &nullUploadProgress{} } @@ -536,11 +535,11 @@ func Upload( ctx: ctx, repo: repository, cacheReader: &hashcache.Reader{}, - stats: &snapshot.Stats{}, + stats: &Stats{}, progress: progress, } - s := &snapshot.Manifest{ + s := &Manifest{ Source: *sourceInfo, } diff --git a/fs/repofs/upload_progress.go b/snapshot/upload_progress.go similarity index 97% rename from fs/repofs/upload_progress.go rename to snapshot/upload_progress.go index 1a9325ba2..ab2292617 100644 --- a/fs/repofs/upload_progress.go +++ b/snapshot/upload_progress.go @@ -1,4 +1,4 @@ -package repofs +package snapshot // UploadProgress is invoked by by uploader to report status of file and directory uploads. type UploadProgress interface { diff --git a/fs/repofs/upload_test.go b/snapshot/upload_test.go similarity index 90% rename from fs/repofs/upload_test.go rename to snapshot/upload_test.go index eff9a7b78..86e0ec91b 100644 --- a/fs/repofs/upload_test.go +++ b/snapshot/upload_test.go @@ -1,4 +1,4 @@ -package repofs +package snapshot import ( "context" @@ -11,7 +11,6 @@ "github.com/kopia/kopia/blob/filesystem" "github.com/kopia/kopia/internal/mockfs" "github.com/kopia/kopia/repo" - "github.com/kopia/kopia/snapshot" "testing" ) @@ -91,12 +90,12 @@ func TestUpload(t *testing.T) { defer th.cleanup() ctx := context.Background() - s1, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, nil, progress) + s1, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, nil, progress) if err != nil { t.Errorf("Upload error: %v", err) } - s2, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, s1, progress) + s2, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, s1, progress) if err != nil { t.Errorf("Upload error: %v", err) } @@ -121,7 +120,7 @@ func TestUpload(t *testing.T) { // Add one more file, the s1.RootObjectID should change. th.sourceDir.AddFile("d2/d1/f3", []byte{1, 2, 3, 4, 5}, 0777) - s3, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, s1, progress) + s3, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, s1, progress) if err != nil { t.Errorf("upload failed: %v", err) } @@ -142,7 +141,7 @@ func TestUpload(t *testing.T) { // Now remove the added file, OID should be identical to the original before the file got added. th.sourceDir.Subdir("d2", "d1").Remove("f3") - s4, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, s1, progress) + s4, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, s1, progress) if err != nil { t.Errorf("upload failed: %v", err) } @@ -160,7 +159,7 @@ func TestUpload(t *testing.T) { t.Errorf("unexpected s4 stats: %+v", s4.Stats) } - s5, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, s3, progress) + s5, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, s3, progress) if err != nil { t.Errorf("upload failed: %v", err) } @@ -188,7 +187,7 @@ func TestUpload_TopLevelDirectoryReadFailure(t *testing.T) { th.sourceDir.FailReaddir(errTest) ctx := context.Background() - s, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, nil, progress) + s, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, nil, progress) if err != errTest { t.Errorf("expected error: %v", err) } @@ -205,7 +204,7 @@ func TestUpload_SubDirectoryReadFailure(t *testing.T) { th.sourceDir.Subdir("d1").FailReaddir(errTest) ctx := context.Background() - _, err := Upload(ctx, th.repo, th.sourceDir, &snapshot.SourceInfo{}, nil, progress) + _, err := Upload(ctx, th.repo, th.sourceDir, &SourceInfo{}, nil, progress) if err == nil { t.Errorf("expected error") }