Stray share entries in DB after deleting parent folder
Steps to reproduce
- Create a folder "test"
- Create/upload a file "test/file.txt"
- Share "test/file.txt" with link
- Delete "test"
- Check "oc_shares"
Expected result
The share entry is gone.
Actual result
The share entry still exists. Also, the link share can still be opened and shows a page with an empty file or folder!
Versions
ownCloud 6 (stable6) ownCloud 7 (stable7) ownCloud 8 (stable8) master
@schiesbn I vaguely remember that there were technical issues (maybe performance) if we want to properly delete all shares
Workaround would be to run this https://github.com/owncloud/core/issues/12323 after a deletion (or on a regular basis).
But the other bug is that the link share doesn't give 404 directly.
Another case for Foreign keys? #13143
Yeah...
CC @DeepDiver1975
Setting to 8.1 to keep this in mind...
@jnfrmarks another test case. Can probably be verified by checking that the created link share does not exist any more after deleting the parent folder. (currently if you query it with the OCS Share API you'll see that it still exist)
It looks like shares set directly on the deleted item (file/folder) is deleted here: https://github.com/owncloud/core/blob/master/apps/files_sharing/lib/updater.php#L89
Maybe that code needs to be extended to also do the same for all children. That's the place where I miss something like "SELECT fileid FROM children" ...
I guess a 8.1 scoped solution would be to trigger a background job to delete all orphaned shares (not only the currently deleted one). The query itself can be expensive in case of many orphaned entries with SQLite since we cannot use DELETE + LEFT JOIN (like MySQL allows), so better put it in a background job.
Duplicate of https://github.com/owncloud/core/issues/6985