Skip to content

NF: use File as much as possible #18350

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged

Conversation

Arthur-Milchior
Copy link
Member

While trying to understand how media are accessed, I realize that there are some part of the code that are not ideal.

The name of the media folder (and similarly the database) are sometime hard coded as "collection.media", and sometime obtained by taking the collection file, and replacing .anki2 by .media. Which means that code is not even consistent about where the medias are. Admittedly, the database is named "collection.anki2" everywhere except in test, so it's not actually an issue.

Also, I remarked that the code keep alternating between File and String through the code. This is furthermore complexified by the fact that the String can be a URI or a path and this is not always clear from context.

Sometime we have a string, create a File from it, do file operation, and then transform it into a string again. I find it clearer to use File as much as possible and keep strings:

  • to fetch and save data in the preferences
  • to call back-end function that require a string
  • for URI

While trying to understand how media are accessed, I realize that
there are some part of the code that are not ideal.

The name of the media folder (and similarly the database) are sometime hard coded as
"collection.media", and sometime obtained by taking the collection
file, and replacing .anki2 by .media. Which means that code is not
even consistent about where the medias are. Admittedly, the database
is named "collection.anki2" everywhere except in test, so it's not
actually an issue.

Also, I remarked that the code keep alternating between File and
String through the code. This is furthermore complexified by the fact
that the String can be a URI or a path and this is not always clear
from context.

Sometime we have a string, create a File from it, do file operation,
and then transform it into a string again. I find it clearer to use
File as much as possible and keep strings:
* to fetch and save data in the preferences
* to call back-end function that require a string
* when a media is referenced as a URI.
@david-allison david-allison added Priority-Low cleanup Non functional change that would improve the code readability labels Jun 3, 2025
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

works for me

@mikehardy mikehardy added this pull request to the merge queue Jun 4, 2025
Merged via the queue into ankidroid:main with commit c719bd4 Jun 4, 2025
12 checks passed
@github-actions github-actions bot added this to the 2.21 release milestone Jun 4, 2025
@Arthur-Milchior Arthur-Milchior deleted the media_dir branch June 5, 2025 20:20
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cleanup Non functional change that would improve the code readability Priority-Low
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants