Skip to content

Commit

Permalink
Add RemoveDirOrFile grpc method (#263)
Browse files Browse the repository at this point in the history
* Add RemoveDirOrFile grpc method

* Fix comment
  • Loading branch information
dmerrill6 authored Nov 26, 2020
1 parent 5b732c1 commit 20167d2
Show file tree
Hide file tree
Showing 7 changed files with 3,231 additions and 471 deletions.
21 changes: 21 additions & 0 deletions core/space/services/services_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,24 @@ func (s *Space) addFile(ctx context.Context, sourcePath string, targetPath strin
Bytes: fileSize,
}, err
}

// Removes a file or directory from a bucket
// Note: If removing a file a user has been shared, call the RemoveMember method instead, as this works only for local buckets.
func (s *Space) RemoveDirOrFile(ctx context.Context, path, bucketName string) error {
err := s.waitForTextileInit(ctx)
if err != nil {
return err
}

b, err := s.getBucketWithFallback(ctx, bucketName)
if err != nil {
return err
}

_, err = b.DeleteDirOrFile(ctx, path)
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions core/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Service interface {
TruncateData(ctx context.Context) error
SearchFiles(ctx context.Context, query string) ([]domain.SearchFileEntry, error)
InitializeMasterAppToken(ctx context.Context) (*permissions.AppToken, error)
RemoveDirOrFile(ctx context.Context, path, bucketName string) error
}

type serviceOptions struct {
Expand Down
9 changes: 9 additions & 0 deletions grpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,12 @@ func (srv *grpcServer) CreateFolder(ctx context.Context, request *pb.CreateFolde

return &pb.CreateFolderResponse{}, nil
}

func (srv *grpcServer) RemoveDirOrFile(ctx context.Context, request *pb.RemoveDirOrFileRequest) (*pb.RemoveDirOrFileResponse, error) {
err := srv.sv.RemoveDirOrFile(ctx, request.Path, request.Bucket)
if err != nil {
return nil, err
}

return &pb.RemoveDirOrFileResponse{}, nil
}
1,111 changes: 641 additions & 470 deletions grpc/pb/space.pb.go

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions grpc/pb/space.pb.gw.go

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

16 changes: 15 additions & 1 deletion grpc/proto/space.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ service SpaceApi {
};
}

// Removes a file or dir from a bucket
rpc RemoveDirOrFile(RemoveDirOrFileRequest) returns (RemoveDirOrFileResponse) {
option (google.api.http) = {
delete: "/v1/files"
};
}

// Generates a copy of the file that's accessible through IPFS gateways
rpc GeneratePublicFileLink(GeneratePublicFileLinkRequest) returns (GeneratePublicFileLinkResponse) {
option (google.api.http) = {
Expand Down Expand Up @@ -797,4 +804,11 @@ message GenerateAppTokenRequest {

message GenerateAppTokenResponse {
string appToken = 1;
}
}

message RemoveDirOrFileRequest {
string path = 1;
string bucket = 2;
}

message RemoveDirOrFileResponse {}
Loading

0 comments on commit 20167d2

Please sign in to comment.