Skip to content

Conversation

@bobvanderlinden
Copy link

I ran into issue #160. Not all operating systems are using /usr or /opt and XDG_DATA_DIRS was made to avoid hard-coding paths like /usr and /opt. This PR makes use of XDG_DATA_DIRS while still maintaining compatibility with systems that do not have XDG_DATA_DIRS.

On my system XDG_DATA_DIRS looks like:

$ echo $XDG_DATA_DIRS
/nix/store/mcxhdbhz0wqi3icx6lvc33iaggd02v6v-patchelf-0.12/share:/nix/store/wrkla3l0c3hg9m9bp5mvjj7z4xqv54wz-terminator-2.1.1/share:/nix/store/2bqip8j6v2hxpafpsaahfdq851i01nan-gsettings-desktop-schemas-40.0/share/gsettings-schemas/gsettings-desktop-schemas-40.0:/nix/store/fdjrhdgvhic14jg6llvm6vz2jvgnhfl6-gtk+3-3.24.27/share/gsettings-schemas/gtk+3-3.24.27:/nix/store/k75hslc3jrcb8y5rd92saxbxxkg2hb03-desktops/share:/home/bob.vanderlinden/.nix-profile/share:/etc/profiles/per-user/bob.vanderlinden/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share

Fixes #160
Possible replacement for #125

@bobvanderlinden
Copy link
Author

@jellybob could you have a look?

@bobvanderlinden
Copy link
Author

@janko @minad could you have a look? Not sure if you're also maintainers of the project?

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

(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"])
] + (
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.

Copy link

@giulliano-bueno giulliano-bueno left a comment

Choose a reason for hiding this comment

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

Great work! I left some small comments that would make your code a bit easier to read.

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.

Use $XDG_DATA_DIRS to find the freedesktop.org.xml

2 participants