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

Tag 0.3.7 doesn't respect FREEDESKTOP_MIME_TYPES_PATH env variable #131

Open
prcongithub opened this issue Mar 26, 2021 · 9 comments
Open

Comments

@prcongithub
Copy link

I upgraded mimemagic to 0.3.7 to fix the issue due to yanked versions.

gem 'mimemagic', '0.3.7'

But the downloaded code for the gem doesn't have any reference to the FREEDESKTOP_MIME_TYPES_PATH env variable.

In environments like AWS Lambda where the freedesktop.org.xml is not present in the locations defined in the gem, the deployments are failing due to this.

How could we address this?

@mvz
Copy link

mvz commented Mar 26, 2021

That's odd. If I download version 0.3.7 it contains ext/mimemagic/Rakefile which has the env var.

Note that the variable has to be set at installation time.

@prcongithub
Copy link
Author

We have set the ENV var before the bundle install starts. The problem is, in lambda environments, the file systems are not writable. Only /tmp folder can be used for writing any files. Could that be the reason why the path from ENV is not used by tables.rb while accessing MimeMagic::DATABASE_PATH?
To fix this for now I have forked this gem and added this line:
prcongithub@da68786#diff-fc52eb3b499c02ca79f89e62ac2cc41c160f4759942a36730cb50e89908a5b03R68

@mvz
Copy link

mvz commented Mar 26, 2021

Yes, the file system not being writable could be a problem. What messages are you getting during both installation and use? Does the generated lib/mimemagic/path.rb get written properly? Is the file the ENV var points at present at runtime?

@prcongithub
Copy link
Author

prcongithub commented Mar 26, 2021

We keep getting this error, even after setting the ENV variable to the correct path which is available at runtime.
Directly setting the path the way I did in my fork seems to work though.

"errorMessage": "No such file or directory @ rb_sysopen - /usr/share/mime/packages/freedesktop.org.xml"
"errorType": "Init<Errno::ENOENT>"
"/var/task/vendor/bundle/ruby/2.7.0/gems/mimemagic-0.3.7/lib/mimemagic/tables.rb:60:in `initialize'"
"/var/task/vendor/bundle/ruby/2.7.0/gems/mimemagic-0.3.7/lib/mimemagic/tables.rb:60:in `open'"
"/var/task/vendor/bundle/ruby/2.7.0/gems/mimemagic-0.3.7/lib/mimemagic/tables.rb:60:in `open_mime_database'"
"/var/task/vendor/bundle/ruby/2.7.0/gems/mimemagic-0.3.7/lib/mimemagic/tables.rb:64:in `parse_database'"
"/var/task/vendor/bundle/ruby/2.7.0/gems/mimemagic-0.3.7/lib/mimemagic.rb:8:in `<top (required)>'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:66:in `require'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:66:in `block (2 levels) in require'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:61:in `each'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:61:in `block in require'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:50:in `each'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler/runtime.rb:50:in `require'"
"/var/runtime/gems/bundler-2.2.9/lib/bundler.rb:173:in `require'"
"/var/task/config/application.rb:16:in `<top (required)>'"
"/var/task/app.rb:10:in `require_relative'"
"/var/task/app.rb:10:in `<top (required)>'"
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'"
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'"     

@jellybob
Copy link
Member

I suspect this is related to #121

@ziggythehamster
Copy link

We keep getting this error, even after setting the ENV variable to the correct path which is available at runtime

The ENV isn't read at runtime, only install time. For a Lambda package, you should be building it locally with a vendored gem installation location (e.g., vendor/bundle) and including that in the package. This would then point at the correct location, in theory, as long as the build system and the Lambda system use the same path for it. This is probably not the case, though, so you've got a bit of a problem.

One solution would be to perhaps do this check on install as normal, but also support picking up the ENV on load too.

@jellybob
Copy link
Member

Rubygems and Lambda functions are a pain, and this is going to be particularly painful I’m afraid because we store the full file path at build time, which will be different to the path in the Lambda’s environment. It does sound like checking for the environment variable at runtime and using that if set is probably the best option here.

@trinhcanhphuc
Copy link

trinhcanhphuc commented Mar 29, 2021

Please install shared-mime-info and add FREEDESKTOP_MIME_TYPES_PATH in your environment.
if you use windows or linux, please download from https://gitlab.freedesktop.org/xdg/shared-mime-info/uploads/0440063a2e6823a4b1a6fb2f2af8350f/shared-mime-info-2.0.tar.xz and extract it

@zhenfuxu
Copy link

D:\Ruby27-x64\lib\ruby\gems\2.7.0\extensions\x64-mingw32\2.7.0\mimemagic-0.4.3\mimemagic\path.rb

class MimeMagic
DATABASE_PATH="J:/xzf/cms/shared-mime-info-2.0/freedesktop.org.xml"
end

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

No branches or pull requests

6 participants