Let's say I'm writing a program, and I want it to follow the XDG Base Directory Specification for where it puts its files (app foo uses $XDG_CONFIG_HOME/foo as the directory for configuration files if XDG_CONFIG_HOME is set and non-blank, or ~/.config/foo, or flails with an error if the home directory can't even be resolved).
Is there a correct/specified behavior for the situation where for example XDG_CONFIG_HOME is set and non-blank, but that directory doesn't exist? Or there is no such variable, and ~/.config doesn't exist? Is it expected that my program attempt to create it? Or is the non-existance of that folder considered an error on the environment's/system's part, and my program should avoid doing anything about it (just bail with an error)?
Note: I'm not asking if I should create ~/.config/foo - obviously that's a yes; I'm asking if I should create ~/.config itself, if it doesn't exist.
(To be more pedantic: obviously some program should create them - the question is whether it's solely the system's/desktop's/user's job to do so, or if any program should try creating the relevant folders if they don't exist?)
I've tried reading the XDG Base Directory Specification, which says that when attempting to write its files, the program may create the requisite directory, but it's unclear if this is referring to just the application's specific/"personal" subdirectory in the XDG base folders, or if this is meant for the XDG base folders themselves.
P.S. Usually I have a good idea of what tags to use, but here I'm really uncertain: please edit this post or suggest improvements to give it proper tags.
I'm posting my own very tentative/speculative answer based on my reasoning about the problem, but I would really like a more authoritative/definitive answer.
I think that a general maxim of being helpful and not doing what the user is likely to have asked in error is a good thing to consider: if I do XDG_DATA_HOME=~.l/ocal/share, I might have wanted exactly that, but it's much more likely that I made a typo. It seems logically sound that the most helpful, and least disruptive, thing to do, is to report the lack of the requested XDG directory in such a case.
Also, as I understand it, the goal of the specification is partly to reduce home directory clutter, so it seems counter-productive to willfully do the equivalent of mkdir -p each time.