kcoredirlister: Remove iterator assert, use if instead
In cases where user adds files to a directory which parent directory is not readable for the user, these asserts would cause a crash, since the code would try to iterate over an empty list:
Due to reinsert
using parent folder of visible
, which is hidden
, we have no permissions to read anything in hidden
so we get an empty list. Without if (it != dirItem->lstItems.end())
this will cause a crash.
This would be okay if we did not allow users browse folders that we can read inside folders that we can't read. However, we allow this behavior if user manually types the path to the Dolphin URL bar for example.
Instead we should just check if the iterator has reached it's end, and just silently do nothing instead. If user is inside a hidden folder, we can't really do any updates to our directory listing views etc. anyway.
I also added similar change to remove
since it does same thing as reinsert
, just with one function call less.
A test case for this is following using Dolphin:
- Open Dolphin, Press F7 to open the folder panel
- Go to any folder
- run
mkdir -p hidden/visible
- run
chmod u-r hidden
- run
chmod go-rw hidden
- Type in URL bar
path/hidden/visible
- Add a new folder