Skip to content

feat(cli): add shares clean-orphaned-grants command - #4082

Open
dragonchaser wants to merge 4 commits into
opencloud-eu:mainfrom
dragonchaser:backport-wp3-784
Open

dragonchaser wants to merge 4 commits into
opencloud-eu:mainfrom
dragonchaser:backport-wp3-784

Conversation

@dragonchaser

Copy link
Copy Markdown
Member

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.

@codacy-production

codacy-production Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 critical

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Security 1 critical (1 false positive)

View in Codacy

🟢 Metrics 253 complexity

Metric Results
Complexity 253

View in Codacy

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.

@dragonchaser
dragonchaser marked this pull request as ready for review November 20, 2026 14:48
@dragonchaser
dragonchaser requested a review from butonic November 23, 2026 08:45

@butonic butonic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The reverse pass deletes all shares of a node when it sees no grants:

    if len(grants) > 0 {

    • with --force a failing ListGrants leaves grants nil ... all shares on that node get removed
    • listResourceGrants returns nil, nil when the registry finds no provider and caches that per space:
      providerCache[spaceID] = nil
      so every shared node in that space loses its shares

    A failed or empty lookup must never count as "no grants". And this pass always runs, there is no way to opt out.

  2. --force in the primary pass removes every user/group grant on a node when ListShares fails, because shares is nil and hasMatchingShareForGrant never matches:

    canModify := !args.DryRun && (shareErr == nil || args.Force)
    I'd drop --force or limit it to a single explicit resource.

  3. The dry run changes state. ListShares with a resource id filter ends up in jsoncs3 listSharesByIDs, which removes expired shares and publishes ShareExpired / SpaceMembershipExpired events 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 --help need to say that.

  4. 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 of owncloud/ocis#11804 were deliberately not ported and why. Right now it reads like the PR destroys data.

Should fix:

  • tests. hasMatchingShareForGrant, the orphan / candidate decision, computeBlobPathRelative and renderWalkerPath can 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 ListShares for 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 ListShares reports every grant on the node as a plain ORPHAN without a warning, the warning is only printed when not in a dry run:
    if shareErr != nil && !args.DryRun && !args.Force {
  • --space-id builds StorageSpaceId{OpaqueId: spaceID}, the gateway expects the full storageid$spaceid, but the README says "space-opaque-id":
    Term: &provider.ListStorageSpacesRequest_Filter_Id{Id: &provider.StorageSpaceId{OpaqueId: spaceID}},
    Either document the format or parse it with storagespace.ParseID.
  • both CleanupStaleShares call sites ignore mErr and any cleanup error and set zerolog.SetGlobalLevel as 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.go is 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.sh points 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 PreRunE of the shares parent is fine, cobra does not run a non persistent PreRunE for 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.

mklos-kw and others added 4 commits November 25, 2026 10:00
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants