Skip to content

Commit

Permalink
backup: unbackup, Bucket.ItemsCount for state management
Browse files Browse the repository at this point in the history
  • Loading branch information
maurycy authored Oct 5, 2020
1 parent 8814d68 commit 4d3558c
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 18 deletions.
5 changes: 5 additions & 0 deletions core/textile/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ type BucketInterface interface {
ctx context.Context,
path string,
) (path.Resolved, error)
ItemsCount(
ctx context.Context,
path string,
withRecursive bool,
) (int32, error)
}

type Notifier interface {
Expand Down
35 changes: 35 additions & 0 deletions core/textile/bucket/bucket_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"

"github.com/FleekHQ/space-daemon/core/textile/utils"
"github.com/FleekHQ/space-daemon/log"
"github.com/ipfs/interface-go-ipfs-core/path"
)
Expand Down Expand Up @@ -80,3 +81,37 @@ func (b *Bucket) DeleteDirOrFile(ctx context.Context, path string) (path.Resolve

return b.bucketsClient.RemovePath(ctx, b.Key(), path)
}

// return the recursive items count for a path
func (b *Bucket) ItemsCount(ctx context.Context, path string, withRecursive bool) (int32, error) {
b.lock.RLock()
defer b.lock.RUnlock()

var count int32

dir, err := b.ListDirectory(ctx, path)
if err != nil {
return 0, err
}

count = dir.Item.ItemsCount

if withRecursive {
for _, item := range dir.Item.Items {
if utils.IsMetaFileName(item.Name) {
continue
}

if item.IsDir {
n, err := b.ItemsCount(ctx, item.Path, withRecursive)
if err != nil {
return 0, err
}

count += n
}
}
}

return count, nil
}
9 changes: 7 additions & 2 deletions core/textile/sync/task-executors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ func (s *synchronizer) processRemoveItem(ctx context.Context, task *Task) error

s.notifySyncNeeded()

// TODO: Remove file from mirror
return nil
if err := s.unsetMirrorFileBackup(ctx, path, bucket); err != nil {
return err
}

err := s.deleteFileFromRemote(ctx, bucket, path)

return err
}

func (s *synchronizer) processPinFile(ctx context.Context, task *Task) error {
Expand Down
20 changes: 12 additions & 8 deletions grpc/handlers_textile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
"github.com/FleekHQ/space-daemon/grpc/pb"
)

func parseBucket(b textile.Bucket) *pb.Bucket {
func parseBucket(ctx context.Context, b textile.Bucket) *pb.Bucket {
bd := b.GetData()

itemsCount, _ := b.ItemsCount(ctx, bd.Path, false)

br := &pb.Bucket{
Key: bd.Key,
Name: bd.Name,
Path: bd.Path,
CreatedAt: bd.CreatedAt,
UpdatedAt: bd.UpdatedAt,
Key: bd.Key,
Name: bd.Name,
Path: bd.Path,
CreatedAt: bd.CreatedAt,
UpdatedAt: bd.UpdatedAt,
ItemsCount: itemsCount,

// TODO: Fill these out from metathread + identity service call
Members: []*pb.BucketMember{},
Expand All @@ -31,7 +35,7 @@ func (srv *grpcServer) CreateBucket(ctx context.Context, request *pb.CreateBucke
return nil, err
}

parsedBucket := parseBucket(b)
parsedBucket := parseBucket(ctx, b)
return &pb.CreateBucketResponse{
Bucket: parsedBucket,
}, nil
Expand All @@ -46,7 +50,7 @@ func (srv *grpcServer) ListBuckets(ctx context.Context, request *pb.ListBucketsR
parsedBuckets := []*pb.Bucket{}

for _, b := range buckets {
parsedBucket := parseBucket(b)
parsedBucket := parseBucket(ctx, b)
parsedBuckets = append(parsedBuckets, parsedBucket)
}

Expand Down
16 changes: 13 additions & 3 deletions grpc/pb/space.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion grpc/pb/space.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion grpc/proto/space.proto
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ message Bucket {
repeated BucketMember members = 6;
bool isPersonalBucket = 7;
bool isBackupEnabled = 8;
int32 itemsCount = 9;
}

message CreateBucketResponse {
Expand Down Expand Up @@ -690,4 +691,4 @@ message GetRecentlySharedWithRequest {}

message GetRecentlySharedWithResponse {
repeated FileMember members = 1;
}
}
23 changes: 22 additions & 1 deletion mocks/Bucket.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion swagger/bin_ui/statik.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions swagger/ui/space.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,10 @@
"isBackupEnabled": {
"type": "boolean",
"format": "boolean"
},
"itemsCount": {
"type": "integer",
"format": "int32"
}
}
},
Expand Down

0 comments on commit 4d3558c

Please sign in to comment.