5 const get_basedir : (explicitly_provided : byte[:] -> std.result(byte[:], byte[:]))
8 const get_basedir = { explicitly_provided : byte[:]
9 var try_dir : byte[:] = [][:]
11 if explicitly_provided.len > 0
12 match std.diropen(explicitly_provided)
15 -> `std.Ok std.sldup(explicitly_provided)
17 -> `std.Err std.fmt("dtd.diropen(\"{}\"): {}", explicitly_provided, e)
21 /* Try to open the XDG one */
23 match std.getenv("XDG_DATA_HOME")
26 try_dir = std.pathjoin([d, "sispare"][:])
27 match std.diropen(try_dir)
38 /* Try to open the $HOME one */
39 try_dir = std.pathjoin([ fileutil.homedir(), ".sispare" ][:])
40 match std.diropen(try_dir)
50 -> `std.Err std.fmt("cannot open any directories\nRun something like\n\n mkdir -p ${{XDG_DATA_HOME}}/sispare # or\n mkdir -p ${{HOME}}/.sispare\n\nor provide one with -d")