2

I had a program that worked a few weeks ago and I wiped it out and had to re-install my ruby and rails enviornment and now I can not bundle install the same program because Paperclip requires Mimemagic and apparently the working versions of the gems no longer exist. Any versions of the gem that remain require this freedesktop.org.xml thing which I went to their site and downloaded but I do not understand on a windows machine how to install the freedesktop.org.xml package so that I can use Ruby on Rails again.

Does anyone know how to install the freedesktop.org.xml package/script/whatever it is so that rails will work properly again? If ANY of our apps break now we are going to be a HORRIBLE place due to this. I have been searching for hours and everything references a MAC or Linux, I am on a PC and I can find NOPLACE that has understandable instructions for how to do this on a Windows 10 PC.

Please HELP!

Thank You, Scott

Update: I tried the suggestion to add:

gem 'mimemagic', git: 'git@github.com:mimemagicrb/mimemagic.git', tag: "v#{[0.3.0]}"

into the gemfile and this is the results I get.

[!] There was an error parsing `Gemfile`: unexpected fraction part after numeric literal - . Bundler cannot continue.

 #  from D:/rails/ctrlpanel/Gemfile:22
 #  -------------------------------------------
 #  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
 >  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
 #  source 'https://rubygems.org'
 #  -------------------------------------------

I don't understand what this means? I also don't understand this entire issue? Is there no way that the freedesktop.org.xml thing can be installed on a Windows PC? This seems like this officially kills Ruby on Rails on a Windows PC?

Scott Milella
  • 468
  • 5
  • 10
  • Probably best to just move forward as suggested and migrate to ActiveStorage. [Migration](https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md). That being said the github repo still exists for the time being so you may be able to reference that for now e.g. `gem 'mimemagic', git: 'git@github.com:mimemagicrb/mimemagic.git', tag: "v#{[VERSION NUMBER]}"`. [This Sectio](https://github.com/mimemagicrb/mimemagic#dependencies) explains the installation pretty clearly. Download, place in appropriate location, set environment variable – engineersmnky Apr 09 '21 at 16:42
  • The code to locate the XML file is here: https://github.com/mimemagicrb/mimemagic/blob/v0.3.8/ext/mimemagic/Rakefile . I suggest to set the `FREEDESKTOP_MIME_TYPES_PATH` manually, then place the XML file in that location, and boot your Rails app. – Casper Apr 09 '21 at 16:55
  • Thank You @Casper, now how do I use that code? Is that something I put on my machine and run with ruby and that file? Or how exactly do I use that code? Is that a replacement gem for mimemagic?If yes do I put that in a file and save it as mimemagic.rb? I am very new to Rails and trying to fix an older application that is broken. When you say SET the FREEDESKTOP_MIME_TYPES_PATH are you talking about as a windows system variable? and if yes where is the XML file itself and where do I put it, it mentioned an "appropriate place" and I have no idea what that means? – Scott Milella Apr 09 '21 at 17:03
  • You misunderstood this `tag: "v#{[0.3.0]}"` should be `tag: 'v0.3.0'` I was simply using `#{[VERSION NUMBER]}` as a placeholder. That being said '0.3.0' is not an available version on github. The oldest version tagged on github is "0.3.7" [Here](https://github.com/mimemagicrb/mimemagic/tree/v0.3.7) – engineersmnky Apr 09 '21 at 17:08
  • Thank You @engineersmnky, however I added the line into my gem file and it just sits forever at this prompt: $ bundle install Fetching git@github.com:mimemagicrb/mimemagic.git What am I doing wrong? I did go and download the source code, is there a way I can import that locally? I have never imported a gem locally like that? If you can how do I do it do I just unzip it and point it to a location or? – Scott Milella Apr 09 '21 at 17:26
  • take a look here and try a different syntax [Bundler: Hot to install gems from git repositories](https://bundler.io/guides/git.html) – engineersmnky Apr 09 '21 at 17:35
  • Apparently this is the problem I deleted some cache folders and now it is telling me I needs a key? Fetching git@github.com:mimemagicrb/mimemagic.git git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Where do I get this key from? – Scott Milella Apr 09 '21 at 17:49
  • @ScottMilella That's a separate question, but it looks like you need to add an SSH key to your github account: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account – Tom Lord Apr 09 '21 at 20:59

2 Answers2

4

The old versions of mimemagic were, annoyingly, hard-deleted from rubygems.org because the author became aware that the library was incorrectly licensed as MIT rather than GPLv2.

More recent versions (v0.3.7+) of the library are correctly licensed as MIT.

I tried the suggestion to add:

gem 'mimemagic', git: 'git@github.com:mimemagicrb/mimemagic.git', tag: "v#{[0.3.0]}"

That won't work on two accounts: Firstly you misunderstood the proposition - just writing tag: 'v0.3.0' was all that's needed, but additionally, it appears the mimemagic author has also tried to cover their backs (legally) by untagging the old library versions in github!!!

...But mimemagic still has full source control! So if you want to explicitly install an old version, it's still pretty easy to pin it directly to a git commit!!

For example, look here at the project history.

If you want to install version 0.3.5 of the gem, you can add this to your Gemfile:

gem 'mimemagic', git: 'https://github.com/mimemagicrb/mimemagic', ref: '01f92d86d15d85cfd0f20dabd025dcbd36a8a60f'

It should be pretty easy to find the reference commit for other versions, using the above link to the project's history.

However as noted above, old versions of this project were incorrectly licensed as MIT. If you are unable to include a GPLv2 licensed library in your project (I am not a lawyer, and this is not legal advice...), you should not be using this approach.

For more information on how to specify git branches/tags/commits in a Gemfile, see the documentation: https://bundler.io/guides/git.html

Tom Lord
  • 27,404
  • 4
  • 50
  • 77
1

This issue can be solved by setting FREEDESKTOP_MIME_TYPES_PATH to point to freedesktop.org.xml before installing the gem or running Bundler.

Example:

Step 1:
Right click and save this file as freedesktop.org.xml to C:\.

Step 2:
Set FREEDESKTOP_MIME_TYPES_PATH in the current command prompt (not permanently stored):

> set FREEDESKTOP_MIME_TYPES_PATH=C:\freedesktop.org.xml

Step 3:
Install the gem (or run bundle install) from the same prompt as in step 2:

> gem install mimemagic
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed mimemagic-0.4.3
1 gem installed
Casper
  • 33,403
  • 4
  • 84
  • 79
  • Thank You for the Answer@Capser, now where do I get the freedesktop.org.xml file from? I downloaded the source code from the website https://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/ and I downloaded the source code but there is no freedesktop.org.xml file? Where can I get this XML file from? I understand the rest completely? Am I just missing it on their site somehow? – Scott Milella Apr 09 '21 at 18:42
  • 1
    See my updated answer. I added a copy from my Ubuntu installation as a downloadable link in step 1. – Casper Apr 09 '21 at 18:54
  • Thank You @Casper !!!!!! I Greatly Appreciate the help! As a follow up question is there anyway I can now save that gem locally so if this next version also gets yanked I have some way to recover it? – Scott Milella Apr 09 '21 at 18:56
  • Thanks Again @Casper (not sure how to properly reference a person in this?) I so appreciate the help! Your a life saver! – Scott Milella Apr 09 '21 at 18:57
  • 1
    Please remember to upvote the answer and accept it, so others can also see the solution. You can download gems locally with for example `gem fetch mimemagic`. You can store that file as a copy for safekeeping. – Casper Apr 09 '21 at 18:59
  • 1
    Also see this answer about storing bundled gems for future safekeeping: https://superuser.com/a/489566/89010 – Casper Apr 09 '21 at 19:04
  • Thank You Casper, I did find that version of the gem listed still (for now at least) on rubygems.org and I saw there was a download option so I downloaded it. It appears to be compiled as I couldn't look at it but I am FOR SURE saving it. I did upvote your answer but apparently I am so new it said due to my reputation being under 15 it was recorded but doesn't show? You deserve the bump for sure! If I can repay you I am willing. I am new to coding with Ruby (I know Java well) but I have 30 years with PC's/Windows & related hardware you ever need anything let me know. – Scott Milella Apr 09 '21 at 19:26