Skip to content

Commit

Permalink
review comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed Jun 11, 2024
1 parent c58d61b commit fa11940
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 46 deletions.
20 changes: 17 additions & 3 deletions internal/fs/inode/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,24 @@ func (d *dirInode) DeleteChildDir(
}
childName := NewDirName(d.Name(), name)

// Delete Folder deletes backing object as well as folder (in case of Hierarchical Bucket).
// Unfortunately we have no way to precondition
// Delete the backing object. Unfortunately we have no way to precondition
// this on the directory being empty.
err = d.bucket.DeleteFolder(ctx, childName.GcsObjectName())
err = d.bucket.DeleteObject(
ctx,
&gcs.DeleteObjectRequest{
Name: childName.GcsObjectName(),
Generation: 0, // Delete the latest version of object named after dir.
})

if err != nil {
err = fmt.Errorf("DeleteObject: %w", err)
return
}

if d.bucket.BucketType() == gcs.Hierarchical {
// Delete Folder deletes folder (in case of Hierarchical Bucket).
err = d.bucket.DeleteFolder(ctx, childName.GcsObjectName())
}

if err != nil {
return
Expand Down
26 changes: 3 additions & 23 deletions internal/storage/bucket_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (bh *bucketHandle) BucketType() gcs.BucketType {
}

func (bh *bucketHandle) NewReader(
ctx context.Context,
req *gcs.ReadObjectRequest) (io.ReadCloser, error) {
ctx context.Context,

Check failure on line 86 in internal/storage/bucket_handle.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
req *gcs.ReadObjectRequest) (io.ReadCloser, error) {
// Initialising the starting offset and the length to be read by the reader.
start := int64(0)
length := int64(-1)
Expand Down Expand Up @@ -146,7 +146,7 @@ func (b *bucketHandle) DeleteObject(ctx context.Context, req *gcs.DeleteObjectRe
}

func (b *bucketHandle) StatObject(ctx context.Context,
req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) {
req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) {
var attrs *storage.ObjectAttrs
// Retrieving object attrs through Go Storage Client.
attrs, err = b.bucket.Object(req.Name).Attrs(ctx)
Expand Down Expand Up @@ -468,26 +468,6 @@ func (b *bucketHandle) ComposeObjects(ctx context.Context, req *gcs.ComposeObjec
}

func (b *bucketHandle) DeleteFolder(ctx context.Context, folderName string) (err error) {
if b.BucketType() == gcs.NonHierarchical {
err = b.DeleteObject(
ctx,
&gcs.DeleteObjectRequest{
Name: folderName,
Generation: 0, // Delete the latest version of object named after dir.
})

if err != nil {
return fmt.Errorf("DeleteObject: %w", err)
}
return nil
}

err = b.deleteFolderForHierarchicalBucket(ctx, folderName)

return err
}

func (b *bucketHandle) deleteFolderForHierarchicalBucket(ctx context.Context, folderName string) (err error) {
var notfound *gcs.NotFoundError
var callOptions []gax.CallOption

Expand Down
20 changes: 0 additions & 20 deletions internal/storage/bucket_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,23 +1285,3 @@ func (testSuite *BucketHandleTest) TestDeleteFolderWhenFolderNotExistForHierarch

assert.Equal(testSuite.T(), "DeleteFolder: mock error", err.Error())
}

func (testSuite *BucketHandleTest) TestDeleteFolderWhenObjectExitForNonHierarchicalBucket() {
mockClient := new(MockStorageControlClient)
testSuite.bucketHandle.controlClient = mockClient
testSuite.bucketHandle.bucketType = gcs.NonHierarchical

err := testSuite.bucketHandle.DeleteFolder(context.Background(), TestObjectName)

assert.Nil(testSuite.T(), err)
}

func (testSuite *BucketHandleTest) TestDeleteFolderWhenObjectNotExitForNonHierarchicalBucket() {
mockClient := new(MockStorageControlClient)
testSuite.bucketHandle.controlClient = mockClient
testSuite.bucketHandle.bucketType = gcs.NonHierarchical

err := testSuite.bucketHandle.DeleteFolder(context.Background(), missingObjectName)

assert.Equal(testSuite.T(), "DeleteObject: gcs.NotFoundError: storage: object doesn't exist", err.Error())
}

0 comments on commit fa11940

Please sign in to comment.