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

use XDG_DATA_DIRS to locate mime database #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ext/mimemagic/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ require "rake/clean"

def locate_mime_database
possible_paths = [
(File.expand_path(ENV["FREEDESKTOP_MIME_TYPES_PATH"]) if ENV["FREEDESKTOP_MIME_TYPES_PATH"]),
(File.expand_path(ENV["FREEDESKTOP_MIME_TYPES_PATH"]) if ENV["FREEDESKTOP_MIME_TYPES_PATH"])
Copy link

@giulliano-bueno giulliano-bueno Jan 10, 2022

Choose a reason for hiding this comment

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

[suggestion]
Should you consider creating a small method called listPossiblePaths and avoid having these hard-to-read (IMHO) lines?

For example:

def listPossibleMimePaths
  paths = []
  paths = File.expand_path(ENV["FREEDESKTOP_MIME_TYPES_PATH"] if ENV["FREEDESKTOP_MIME_TYPES_PATH"]
...

paths
end

] + (
if ENV["XDG_DATA_DIRS"]
Copy link

@giulliano-bueno giulliano-bueno Jan 10, 2022

Choose a reason for hiding this comment

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

[suggestion]
If you use ENV.fetch with [] as default you can avoid one extra if statement. Check it here.

ENV["XDG_DATA_DIRS"].
split(':').
map { |data_dir| File.join(data_dir, "mime/packages/freedesktop.org.xml") }
else
[]
end) + [
"/usr/local/share/mime/packages/freedesktop.org.xml",
"/opt/homebrew/share/mime/packages/freedesktop.org.xml",
"/opt/local/share/mime/packages/freedesktop.org.xml",
Expand Down