moved upload functionality to snapshot package

This commit is contained in:
Jarek Kowalski
2017-01-30 20:07:02 -08:00
parent 0195d2740a
commit 81fd499bae
5 changed files with 19 additions and 22 deletions

View File

@@ -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,

View File

@@ -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{}

View File

@@ -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,
}

View File

@@ -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 {

View File

@@ -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")
}