Hitchhikers Guide to Libostree

2 minutes read | 413 words

Aaruni Kaushik

As part of my work, I’m heavily using ostree. Ostree is a git like content addressed store for filesystem trees. Its a really cool technology for distributing software, and is used by many major players in the industry : GnomeOS, rpm-ostree, flatpaks, and so on. While ostree has capability of deploying entire OS trees (hence the name), it can also be used in “user mode” (as opposed to “host mode”), where it manages only a target user repository, instead of the entire host. (Fun fact, ostree has the ability to juggle between different versions of the OS, or even different OSs!)

But if you want your users to use whatever you’re building which relies on OSTree, you cannot rely on your users learning the command line interface to OSTree (and trusting them to setup things in exactly the right way the rest of your program expects.). There’s two ways to invoke OSTree functionality from another program: use the infamous system() call (or its analog in your favorite language), or use the ostree library. The ostree documentation says the following:

We recommend taking a look at the OSTree API, and choose a programming language supported by GObject Introspection to write your buildsystem scripts.

It’s strongly recommended to choose a real programming language for your build system.

So, I looked at using the OSTree library via python. The experience, unfortunately, was less than pleasant. The things work quite well once you figure out how, but the documentation doesn’t really help you get there. THere are man-pages for the standalone program, but for the library, all you get is this wonderful API reference. It tells you what every class is and what every function does, but leaves out the map markers to help you navigate it all. Finally, the only way to do anything reasonable with the library is to either constantly browse the the API reference until you find something which looks like it might work, and then do a lot of trial-and-error, or, use the standalone ostree program as a “reference implementation”, and study the source code of that to learn what the expected solution is supposed to be.

In the following series of posts, I hope to write a beginner friendly guide to libostree, based on my experience, This will serve both as documentation for people new to the project, and also something I can refer back to 6 months down the line, instead of diving into the source code of ostree agian.