lensfun: How database files are found and loaded

lensfun 0.3.4.0

How database files are found and loaded

In a typical application, all XML files are loaded automatically at startup. If the same object is defined in multiple files, later definitions override earlier definitions, e.g. user can override system-wide definitions by placing appropriately formatted XML files in its home directory.

A typical application will initialize the lens database by calling the method lfDatabase::Load() with no parameters. This method searches for all available XML files and loads them, ignoring files with errors.

The main place where Lensfun looks for database files usually is /usr/share/lensfun/version_x, where x is the database format version (Database format versions). However, this is configurable at compilation time, and for locally compiled Lensfun, it is mostly /usr/local/share/lensfun/version_x. A special directory is /var/lib/lensfun-updates/version_x: If it exists and contains a newer database, it is loaded instead of the main place. On Windows, this is something like C:\Documents and Settings\%User%\something\version_x but I'm not sure exactly :-).

“Newer database” means that the file timestamp.txt, which is amongst the XML files, contains a larger value. This value is the database timestamp in UNIX time.

After having read the global database, the user's home directory is searched. Usually, this is ~/.local/share/lensfun. The exact path can be found in the variable lfDatabase::HomeDataDir. The subdirectory updates/version_x may contain a user-specific DB update. This represents an alternative to /var/lib/lensfun-updates/version_x for which no root priviledges are needed.

~/.local/share/lensfun/version_x is also scanned with higher priority than the one without the version_x, so that the user can set entries specific for a database version. This is useful only if you need to maintain two or more different Lensfun versions on your system.

So sum it up for Linux and other Unix-like platforms, the load order is:

1. the directory Lensfun's database was installed into (usually /usr/share/{local/}lensfun/version_x), or /var/lib/lensfun-updates/version_x, or ~/.local/share/lensfun/updates/version_x, whatever is newest
2. ~/.local/share/lensfun
3. ~/.local/share/lensfun/version_x

Another way to load database file is to load them one by one. For this you call lfDatabase::Load(const char *) for every XML file that must be loaded.