There are several places in the app where we rely on the ~ path shortcut, or the $HOME environment variable respectively. (For example when processing the settings.yml file.) However, there are scenarios where the app (or parts of it) are run under a different user, e.g. root, or with sudo, in which case ~ would erroneously resolve to /root instead of /home/tinypilot.
This PR makes sure that the app always uses /home/tinypilot for accessing TinyPilot-specific objects, independent of what the $HOME environment variable contains. TinyPilot-specific objects are:
I suggest that we don’t just hard-code the /home/tinypilot path as is, because that would make local development more inconvenient – you always would need to initialize and switch to a tinypilot user before being able to start developing. Therefore, I introduced a new environment variable (TINYPILOT_HOME_DIR), that lets us overrride the /home/tinypilot default. Unfortunately, we cannot put this variable into dev_app_settings.cfg, since the app config can only be read during a Flask request execution context, but not at initialization time (at least not in a “clean” way). To me, the env.abs_path_in_home_dir helper function (as proposed here) wouldn’t be too bad either, though.
Resolves https://github.com/tiny-pilot/tinypilot/issues/1571.
There are several places in the app where we rely on the
~
path shortcut, or the$HOME
environment variable respectively. (For example when processing thesettings.yml
file.) However, there are scenarios where the app (or parts of it) are run under a different user, e.g.root
, or withsudo
, in which case~
would erroneously resolve to/root
instead of/home/tinypilot
.This PR makes sure that the app always uses
/home/tinypilot
for accessing TinyPilot-specific objects, independent of what the$HOME
environment variable contains. TinyPilot-specific objects are:settings.yml
logs/**
(i.e., update result logs).flask-secret-key
tinypilot.db
app_settings.cfg
(no change needed, as this is already referenced in an absolute manner)I suggest that we don’t just hard-code the
/home/tinypilot
path as is, because that would make local development more inconvenient – you always would need to initialize and switch to atinypilot
user before being able to start developing. Therefore, I introduced a new environment variable (TINYPILOT_HOME_DIR
), that lets us overrride the/home/tinypilot
default. Unfortunately, we cannot put this variable intodev_app_settings.cfg
, since the app config can only be read during a Flask request execution context, but not at initialization time (at least not in a “clean” way). To me, theenv.abs_path_in_home_dir
helper function (as proposed here) wouldn’t be too bad either, though.