Skip to content

fix(files_sharing): don't abort share:list when orphaned shares exist - #62060

Open
Fantu wants to merge 1 commit into
nextcloud:masterfrom
M2Rbiz:fix/share-list-orphan-shares
Open

fix(files_sharing): don't abort share:list when orphaned shares exist#62060
Fantu wants to merge 1 commit into
nextcloud:masterfrom
M2Rbiz:fix/share-list-orphan-shares

Conversation

@Fantu

@Fantu Fantu commented Jul 13, 2026

Copy link
Copy Markdown

Summary

For several years I have been administering a server where 50–60 people work mainly with Nextcloud and Onlyoffice, and over the years they have created thousands of user shares.

When someone asked me to restore files from backup, in the cases involving shares between users they often could not tell me the exact origin of the shared file, and in two cases I wasted a lot of time because of that.

Since occ had no share:list command at the time, I had written an external script that generated a similar list every day, so that during a restore I could quickly find the origin of a share by looking at that list in a backup from a day when the share still existed.

Nextcloud 32 finally added share:list to occ, but unfortunately on that server (and I suppose in many other cases) it was unusable: some orphaned shares are always present, and a single one is enough to make the whole command abort.

I considered working around it by always deleting the orphaned shares first, but I don't want to lose the few cases where a restore can actually repair a share, nor risk needlessly removing shares because of temporary problems with the SMB file server or something else.

So I made this change so that the command also works when orphaned shares exist.

Note that orphaned shares are not skipped but included in the list, even though the most important piece of information (the source path) is missing and shown as empty/null. For cases like mine this still has some value: from the orphaned entries you can immediately tell whether a share with the exact name (or a similar one) mentioned by the user actually existed, and who it was shared with. This is already a small improvement over my old external script, which excluded orphaned shares, so I had to dig through several backups just to confirm that the share had existed at all and what it was called. I think keeping the orphaned entries visible where possible can be useful to others as well.

I also added unit tests to catch possible regressions; this command previously had no tests at all.

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

`occ share:list` resolved the source node of every share without
handling NotFoundException, so a single orphaned share (e.g. the source
file was deleted from disk externally, or is pending removal by
DeleteOrphanedSharesJob) aborted the whole command with "Node for share
not found" and produced no output at all.

Catch the exception in both places that resolve the share node: orphaned
shares are now listed with a null source-path, and the --parent filter
skips them instead of crashing.

Add unit tests for the command (previously untested), covering listing
with an orphaned share present and the --parent filter with and without
--recursive.

Closes nextcloud#61949

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
@Fantu
Fantu requested a review from a team as a code owner July 13, 2026 12:23
@Fantu
Fantu requested review from icewind1991, leftybournes, provokateurin and salmart-dev and removed request for a team July 13, 2026 12:23
@Fantu

Fantu commented Jul 13, 2026

Copy link
Copy Markdown
Author

I have now also tested the fix on a small production server running Nextcloud 32.0.11 (patch applied manually to ListShares.php): it works as expected, the command lists everything even with orphaned shares present.

@icewind1991 thank you for adding the share:list command, is very useful.
This PR makes the command usable also when orphaned shares exist; what do you think?

@CarlSchwan CarlSchwan added 3. to review Waiting for reviews community pull requests from community labels Jul 14, 2026
@CarlSchwan CarlSchwan added this to the Nextcloud 35 milestone Jul 14, 2026
@CarlSchwan

Copy link
Copy Markdown
Member

/backport to stable33

@CarlSchwan

Copy link
Copy Markdown
Member

/backport to stable34

@Fantu

Fantu commented Jul 14, 2026

Copy link
Copy Markdown
Author

@CarlSchwan thanks for the fast review, can you please also backports to nc 32? I already tested on it I'm already using on production server (nc 32)
I take a look on failed workflow but seems failing on things not related to real issue of the commit added in this PR, or I'm wrong?

@CarlSchwan

Copy link
Copy Markdown
Member

/backport to stable32

@CarlSchwan

Copy link
Copy Markdown
Member

Some of the CI workflow are a bit flacky. I will restart them if needed, just don't rebase your PR :)

@Fantu

Fantu commented Jul 14, 2026

Copy link
Copy Markdown
Author

thanks for the reply and backport to nc32
I don't think this will need rebase even if not applied shortly it's a small change and to a file that seems rarely touched at the moment, I also applied it quickly and easily manually to the production server with nc 32

@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews backport-request community pull requests from community feedback-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: occ share:list aborts with "Node for share not found" if any orphaned share exists

2 participants