Skip to content

Fix: do not store entries for non-existent folders#137

Closed
kaihowl wants to merge 1 commit intoSidOfc:masterfrom
kaihowl:fix-empty-folder
Closed

Fix: do not store entries for non-existent folders#137
kaihowl wants to merge 1 commit intoSidOfc:masterfrom
kaihowl:fix-empty-folder

Conversation

@kaihowl
Copy link
Copy Markdown

@kaihowl kaihowl commented Mar 16, 2024

Repro:

edit .
call input('hit enter')
echomsg 'create inital folder'
!mkdir -p hello/ && touch hello/a && touch hello/b
echomsg 'created inital folder'
edit hello/
echomsg 'opened hello'
call input('hit enter')
echomsg 'deleting folder'
!rm -rf hello/
echomsg 'deleted folder'
call input('hit enter')
echomsg 'creating folder'
!mkdir -p hello/ && touch hello/a && touch hello/b
echomsg 'created folder folder'
call input('hit enter')

When running the above script, one ends up with the folder hello permanently empty in every carbon view. Despite the folder having children on the disk.

Fixed by distinguishing an empty folder from a non-existent folder in entry:get_children. A failure from fs_scandir is otherwise indistinguishable from an empty but existing folder.

@SidOfc
Copy link
Copy Markdown
Owner

SidOfc commented Mar 18, 2024

I see indeed. I haven't checked it out yet, but it seems related to edit hello/ and then deleting hello/. If I'm not inside this folder in some view it all works as expected. As for this fix, I would expect get_children to always return something which can be looped over (i.e. a table, even if empty). Checking for existence should be the task of some other (perhaps new) method.

I think I'm going to look at this from a different angle since if you're viewing hello/ with carbon and it gets deleted you're still in there after deletion which is basically impossible.

The problem lies a bit deeper than just some wrongly cached data, cheers for bringing it to my attention and bringing a PR nonetheless! I'll look at it a bit more in-depth somewhere this week 👍

@kaihowl
Copy link
Copy Markdown
Author

kaihowl commented Mar 18, 2024

@SidOfc, you are right: One could also go ahead and define what happens if a view is open and the root folder gets deleted. Nonetheless, having the method get_children just swallow the potential error seems wrong to me. If you are saying get_children should only be called on an existing folder (precondition) and for that you want a separate method: That seems clean as well.

I only brought the PR to show the minimal changes needed to have somewhat saner behavior. Maybe you could consider bringing in this 'breakfix' first and then go for a bigger refactoring? :)

And because I never get tired of saying so: Thank you very much for investing time in this plugin. It is still the best file viewer I have used so far in nvim.

SidOfc added a commit that referenced this pull request Mar 18, 2024
@SidOfc
Copy link
Copy Markdown
Owner

SidOfc commented Mar 18, 2024

No problem, happy to hear it still serves you well :)

As for merging in this fix, I've already gone ahead and wrote a small patch in a branch patch/removed-view. What it does is while inside a folder which is removed, it closes the view and scrubs it from the list of active views.

Furthermore, if the view was the only window, a regular :Carbon / :Explore is triggered to open the file viewer in the current directory.

After implementing this I could no longer reproduce the "hanging" empty folder. Can you confirm this fixes the problem for you as well? (Perhaps some OS differences make this a "works on my machine" kind of thing)

@kaihowl
Copy link
Copy Markdown
Author

kaihowl commented Mar 18, 2024

Can confirm that the branch also works in my environment. Thank you!

@SidOfc
Copy link
Copy Markdown
Owner

SidOfc commented Mar 18, 2024

Thanks for confirming! I'll make proper release later today so that you can revert back to master. I'll close this PR as it won't be necessary anymore. Thanks for the effort though, much appreciated!

@SidOfc SidOfc closed this Mar 18, 2024
@SidOfc SidOfc mentioned this pull request Mar 18, 2024
@kaihowl
Copy link
Copy Markdown
Author

kaihowl commented Mar 18, 2024

I see that 0.20.1 is released with the fix included. With nvim using the plugin from master, the above reproduction no longer shows the issue. Thank you for the quick fix and support!

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.

2 participants