Skip to main content
  1. Decisions/

Conform to the XDG Base Directory Specification

·378 words·2 mins
Agent IO
Author
Agent IO
Table of Contents
Store IO state and temporary files in standard locations.

Originally IO stored its files in the directory where it was run. These files included:

  • io.db, a SQLite database of IO configuration,
  • traffic.db, a SQLite database of traffic recorded by IO,
  • envoy.log, the main Envoy log,
  • access.log, a log of Envoy traffic,
  • debug.log, a log file written from IO’s stderr.

With this, different IO configurations could exist in different directories and could be easily selected by starting IO in the corresponding directory.

Recently while exploring neovim, I discovered the XDG Base Directory Specification and decided to modify IO to conform to this.

Currently this means that most of IO’s files are kept under XDG_DATA_HOME (which defaults to ~/.local/share) in the io subdirectory.

A few other files are under XDG_CACHE_HOME (the default for this is ~/.cache) in the io/run subdirectory:

  • bootstrap.json, the Envoy startup configuration (previously stored in a random tmp directory),
  • files associated with IO sockets on platforms where Linux Abstract Sockets aren’t available.

Container builds set XDG_DATA_HOME=/ and XDG_CACHE_HOME=/ and had no observable change (they already stored IO files in /io).

Pros
#

  • IO can be started from any directory and runs from a standard set of state files. This eliminates the random io.db files that were showing up in directories where I unintentionally started IO.
  • This subjectively changes my experience as an IO user. IO feels much more like a built-in part of my system that I can easily start and stop. This seems particularly nice when I’m using IO as the “IO” for my laptops.
  • XDG_CACHE_HOME is a nice place to put temporary files. By suggesting a home for socket files, it cleared the way for MacOS support.

Cons
#

  • Have you heard of the XDG Base Directory Specification? Linux users should get familiar with it, but might not be.
  • Quickly switching between IO configurations is a bit more difficult, but IO’s --base-id flag gives us a nice alternate way to do this. This flag sets Envoy’s Base ID, which allows Envoy to use different shared memory regions so that multiple Envoys can be run on a single system. Now we also use it to name the IO directory, so that with a base id of 7 (for example), IO state is stored in $XDG_DATA_HOME/io-7 and run files are in $XDG_CACHE_HOME/io-7/run.

Comment with ATProto
#