Skip to content

Commit

Permalink
purge spaces in the storage driver
Browse files Browse the repository at this point in the history
Spaces can now be purged in a two step process.
The code currently doesn't purge the blobs though.
  • Loading branch information
David Christofas committed Jan 17, 2022
1 parent c030825 commit bb1648e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/purge-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Delete shares when purging spaces

Implemented the second step of the two step spaces delete process.
The first step is marking the space as deleted, the second step is actually purging the space.
During the second step all shares, including public shares, in the space will be deleted.
When deleting a space the blobs are currently not yet deleted since the decomposedfs will receive some changes soon.

https://github.com/cs3org/reva/pull/2431
44 changes: 42 additions & 2 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,37 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up

// DeleteStorageSpace deletes a storage space
func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) error {
opaque := req.Opaque
var purge bool
if opaque != nil {
_, purge = opaque.Map["purge"]
}

if purge {
ip := fs.lu.InternalPath(req.Id.OpaqueId)
matches, err := filepath.Glob(ip)
if err != nil {
return err
}

// TODO: remove blobs
if err := os.RemoveAll(matches[0]); err != nil {
return err
}

matches, err = filepath.Glob(filepath.Join(fs.o.Root, "spaces", spaceTypeAny, req.Id.OpaqueId))
if err != nil {
return err
}
if len(matches) != 1 {
return fmt.Errorf("delete space failed: found %d matching spaces", len(matches))
}
if err := os.RemoveAll(matches[0]); err != nil {
return err
}
return nil
}

spaceID := req.Id.OpaqueId

matches, err := filepath.Glob(filepath.Join(fs.o.Root, "spaces", spaceTypeAny, spaceID))
Expand All @@ -352,7 +383,7 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De
}

if len(matches) != 1 {
return fmt.Errorf("update space failed: found %d matching spaces", len(matches))
return fmt.Errorf("delete space failed: found %d matching spaces", len(matches))
}

target, err := os.Readlink(matches[0])
Expand All @@ -374,7 +405,16 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De
if err != nil {
return err
}
return nil

trashPathMatches, err := filepath.Glob(node.InternalPath() + ".T.*")
if err != nil {
return err
}
if len(trashPathMatches) != 1 {
return fmt.Errorf("delete space failed: found %d matching trashed spaces", len(matches))
}
trashPath := trashPathMatches[0]
return os.Symlink(trashPath, filepath.Join(filepath.Dir(matches[0]), filepath.Base(trashPath)))
}

// createHiddenSpaceFolder bootstraps a storage space root with a hidden ".space" folder used to store space related
Expand Down

0 comments on commit bb1648e

Please sign in to comment.