Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for desktop files in all subdirectories of app dirs #370

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

yawor
Copy link
Contributor

@yawor yawor commented Dec 26, 2024

Fixes #367

@yawor
Copy link
Contributor Author

yawor commented Dec 26, 2024

Do not merge yet. I need to fix something

@yawor
Copy link
Contributor Author

yawor commented Dec 26, 2024

Ok, it's fixed now. I've moved the seen directory check to be better optimized.

file_path = os.path.realpath(os.path.join(d, file_name))
if os.path.isdir(file_path):
app_dirs.insert(0, file_path)
continue
__process_desktop_file(file_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you could add

if not os.path.exists(file_path):
    continue

to avoid a crash on launch if the directory contains a broken symlink

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good idea. I haven't thought of that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pol-rivero I've also been thinking whether or not check if the file has a .desktop extension before passing it to __process_desktop_file method.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also had the same doubt when writing it originally, by decided not to check it for 2 reasons:

  1. It's not necessary. If our code works fine without this restriction, we shouldn't enforce it (see Robustness principle).
  2. The Desktop Entry Specification technically does allow desktop files to use extensions other than .desktop (notice the use of "Desktop entry files should have the .desktop extension" instead of "must" or equivalent).

@yawor
Copy link
Contributor Author

yawor commented Dec 27, 2024

I've added check if the file exists.
I've also added handing of OSError when listing files in the directory in case the directory permissions don't allow listing its content by the current user. The directory is skipped in that case.
Added OSError handling in __process_desktop_file method when opening the file to be sure it can be opened.
Added UnicodeDecodeError in __process_desktop_file method when reading from opened file, as it can be raised if a binary file is opened in text mode (just to cover some edge cases that user maybe put some binary file there by accident).

@pol-rivero
Copy link
Contributor

pol-rivero commented Dec 27, 2024

Sounds good! This should now cover lots of edge cases. Looks good to merge.
@nwg-piotr

@nwg-piotr
Copy link
Owner

Very well then.

@nwg-piotr nwg-piotr merged commit 00357f5 into nwg-piotr:master Dec 27, 2024
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.

[BUG] crash on launch (Scratchpad module?)
3 participants