My *nix world

How to patch a baobab

For those who were around Linux in the last years the Gnome utility called Disk Usage Analyzer (aka baobab) is not a secret anymore.

disk usage analyzer baobab open folder

source: http://www.marzocca.net/linux/baobab/figures/baobab_fullscan.png

It is a gnome-utils, which perhaps works perfectly with the Gnome desktop environment, but in Gentoo with Xfce4 however it seems to have an issue: whenever you right-click on a folder, in order to open it (with your default editor as defined in "MIME type editor"), it wouldn't open but instead will show an error message like this:

disk usage analyzer baobab open folder

click to zoom

If you dig into your baobab's sources you will find that the message comes from open_file_with_application function within baobab-utils.c source code.

One of the reasons I love Linux (especially Gentoo distro) is because I have access to the source code and I don't have to wait (forever) for a patch from the community instead I can patch the code myself right away.

The problem, in our case, starts with the line #21 (see my code snapshot above) because the function g_app_info_get_default_for_type is not capable of returning the right GAppInfo when it's not called from within Gnome desktop environment. This is neither a bug in baobab code or gnome-utils but a missing patch in Gentoo distro about the gnome-utils-2.32.0-r2 package. Maybe is not a missing patch in Gentoo but a problem that I have locally so I'm going to patch it.

In my dirty lazy patch I will use a function from xdg-utils library, which should be installed on all platforms where you have X Window System installed. The function we are going to use it's called xdg-open and its purpose is to "open a file or URL in the user's preferred application".

So, comment or remove the code between line 24-30 (like in my code snapshot above) and patch it with the following:

So after all this changes your function code should looks like this:

Now, the question is: how do you install your new patch into Gentoo?

I found two different ways of achieving this: the patch-forever way and the patch-and-go way. In the permanent way we prepare the system to be able to merge our patch automatically even after a system update. In the volatile way we just prepare the system to merge manually our patch, but if you call emerge then the system will use the original not patched source code instead of the patched one.

The patch-forever way

This method supposed to create our own custom overlay for this package. Before doing that let's tell the emerge where is the root directory for our custom overlays: edit the /etc/make.conf and add a line like:

  1. Make sure the directory /usr/local/portage exists, and if not then create it.
  2. Create the folder structure for our custom overlay:
  1. Copy the original overlay file to our custom overlay directory:

If the original overlay contains other patch files that you want also to apply, then copy them to your local overlay in the ./files directory:
  1. Create our the patch file starting from the "buggy" source code
    1. fetch and unpack the source code:
    2. copy the buggy source code to our custom overlay directory structure:
      1. cp /var/tmp/portage/gnome-extra/gnome-utils-2.32.0-r2/work/gnome-utils-2.32.0/baobab/src/baobab-utils.c patch/{a,b}/baobab/src/
    3. edit the patch/b/baobab/src/baobab-utils.c and change those lines (24-30) as indicated few paragraphs above, then save the changes
    4. finally we create the real patch file by comparing the original with the changed file:
  1. Instruct our custom overlay file to take into consideration also our custom patch(es) created above. So we have to edit the gnome-utils-2.32.0-r2.ebuild file:
    1. make sure that you inherits also the eutils package by changing the inherit line (at the top of the file) like the one below:
    2. add the following function at the end of the file then save the changes and exit:
    3. Now make sure you communicate to ebuild that your ebuild overlay file has changed:
  2. emerge the custom overlay that contains our patch:

The patch-and-go way

For this we are going to use ebuild instead of emerge tool. It will help us to prepare the build environment, to fetch the baobab original source code, to unpack the source code into our build environment, to compile the source code, to install it int the build environment and finally to emerge it into Gentoo live system.

Run the following commands:


This is the moment when you should edit/patch the original code with the one I showed you above.

If you have changed/saved your code then continue with the next steps to compile,install and merge the installation into the live Gentoo system folder.


Whatever method you embraced, if everything went OK then your baobab should be already patched 😉

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

 
The following two tabs change content below.
How to patch a baobab

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
How to patch a baobab

Latest posts by Eugen Mihailescu (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: