Repository navigation
feat(cli): add shares clean-orphaned-grants command - #4082
dragonchaser wants to merge 4 commits into
Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 1 critical (1 false positive) |
🟢 Metrics 253 complexity
Metric Results Complexity 253
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
butonic
left a comment
There was a problem hiding this comment.
The overall approach is fine, but the destructive paths treat "I could not read X" as "X is empty", and the dry run is not side effect free. Blocking IMO:
-
The reverse pass deletes all shares of a node when it sees no grants:
opencloud/opencloud/pkg/command/shares.go
Line 511 in 6481ee9
- with
--forcea failingListGrantsleavesgrantsnil ... all shares on that node get removed listResourceGrantsreturnsnil, nilwhen the registry finds no provider and caches that per space:so every shared node in that space loses its sharesopencloud/opencloud/pkg/command/shares.go
Line 612 in 6481ee9
A failed or empty lookup must never count as "no grants". And this pass always runs, there is no way to opt out.
- with
-
--forcein the primary pass removes every user/group grant on a node whenListSharesfails, becausesharesis nil andhasMatchingShareForGrantnever matches:I'd dropopencloud/opencloud/pkg/command/shares.go
Line 426 in 6481ee9
--forceor limit it to a single explicit resource. -
The dry run changes state.
ListShareswith a resource id filter ends up in jsoncs3listSharesByIDs, which removes expired shares and publishesShareExpired/SpaceMembershipExpiredevents while listing:if share.IsExpired(s) { if err := m.removeShare(ctx, s, false); err != nil {
Both passes call it for nodes, so a dry run on a real instance expires shares and sends notifications. At least the README and
--helpneed to say that. -
The PR description says the non dry run "deleted the share lists of all scanned spaces" and
--force"wiped the share-manager metadata even in a dry run". AFAICT that was the on disk healers, which 6481ee9 dropped. Please reword it: say which parts ofowncloud/ocis#11804were deliberately not ported and why. Right now it reads like the PR destroys data.
Should fix:
- tests.
hasMatchingShareForGrant, the orphan / candidate decision,computeBlobPathRelativeandrenderWalkerPathcan be tested with mocked selectors. 0.82% diff coverage for a command that deletes grants and shares is not enough. - the reverse pass walks the whole tree a second time and calls
ListSharesfor every node, which loads the full share list of the space each time. Listing the shares per space once and then checking grants only for those resources would be much cheaper ... and limits the blast radius of 1. - in a dry run a failing
ListSharesreports every grant on the node as a plainORPHANwithout a warning, the warning is only printed when not in a dry run:opencloud/opencloud/pkg/command/shares.go
Line 394 in 6481ee9
-
--space-idbuildsStorageSpaceId{OpaqueId: spaceID}, the gateway expects the fullstorageid$spaceid, but the README says "space-opaque-id":Either document the format or parse it withopencloud/opencloud/pkg/command/shares.go
Line 745 in 6481ee9
storagespace.ParseID. - both
CleanupStaleSharescall sites ignoremErrand any cleanup error and setzerolog.SetGlobalLevelas a side effect. It is the same block twice, so make it one helper that returns the error.
Smaller things:
- the change in
services/graph/pkg/service/v0/base.gois a no-op,share.GetPermissions().GetPermissions()is already nil safe. Drop it or explain it. // Test locally with: simple-opencloud-blobs/test_clean_orphaned_grants.shpoints to a script that does not exist, and the directory layout comment still talks about "Phase 1,3,4" of the dropped healers (it belongs to #4081 anyway).- dropping the
PreRunEof thesharesparent is fine, cobra does not run a non persistentPreRunEfor subcommands, so it never ran. Worth a line in the commit message. - this is stacked on #4081, the first two commits should go away once that is merged.
AI assistance: Claude Code (claude-opus-5-5) drafted this review.
They rewrote or deleted the share lists of all scanned spaces on disk, and --force deleted all share-manager metadata, even in a dry run. The scans and the gateway calls stay; the stale-share cleanup no longer runs in a dry run. Assisted-by: Claude Code:claude-opus-5-5
…pe its destructive options Assisted-by: Claude Code:claude-opus-5-5
6481ee9 to
314ff13
Compare
Adds opencloud shares clean-orphaned-grants, which reports storage grants without a share (and shares without a grant) and removes them with --dry-run=false, and makes move-stuck-upload-blobs fail on a wrong base path; builds on the move-stuck-upload-blobs backport. Caution: on a test instance the non-dry run deleted the share lists of all scanned spaces from disk, and --force wiped the share-manager metadata even in a dry run.
AI assistance: Claude Code (claude-opus-5-5) ported the commits to the cobra CLI and tested the command on a throwaway instance.