Skip to content

Commit 37577eb

Browse files
authored
os: document behavior of cache_dir/0, data_dir/0, state_dir/0, local_bin_dir/0 and vtmp_dir/0 (#26412)
1 parent ce35b07 commit 37577eb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

vlib/os/os.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ fn xdg_home_folder(ename string, lpath string) string {
907907
// `$XDG_CACHE_HOME` defines the base directory relative to which user specific
908908
// non-essential data files should be stored. If `$XDG_CACHE_HOME` is either not set
909909
// or empty, a default equal to `$HOME/.cache` should be used.
910+
// Note: This function ensures that the returned directory exists and panics if directory creation fails.
910911
pub fn cache_dir() string {
911912
return xdg_home_folder('XDG_CACHE_HOME', '.cache')
912913
}
@@ -917,6 +918,7 @@ pub fn cache_dir() string {
917918
// This directory is defined by the environment variable `$XDG_DATA_HOME`.
918919
// If `$XDG_DATA_HOME` is either not set or empty, a default equal to
919920
// `$HOME/.local/share` should be used.
921+
// Note: This function ensures that the returned directory exists and panics if directory creation fails.
920922
pub fn data_dir() string {
921923
return xdg_home_folder('XDG_DATA_HOME', '.local/share')
922924
}
@@ -931,6 +933,7 @@ pub fn data_dir() string {
931933
// It may contain:
932934
// * actions history (logs, history, recently used files, …)
933935
// * current state of the application that can be reused on a restart (view, layout, open files, undo history, …)
936+
// Note: This function ensures that the returned directory exists and panics if directory creation fails.
934937
pub fn state_dir() string {
935938
return xdg_home_folder('XDG_STATE_HOME', '.local/state')
936939
}
@@ -939,6 +942,7 @@ pub fn state_dir() string {
939942
// It is compatible with stributions, following the XDG spec from https://specifications.freedesktop.org/basedir-spec/latest/ :
940943
// > User-specific executable files may be stored in `$HOME/.local/bin`.
941944
// > Distributions should ensure this directory shows up in the UNIX $PATH environment variable, at an appropriate place.
945+
// Note: This function ensures that the returned directory exists and panics if directory creation fails.
942946
pub fn local_bin_dir() string {
943947
return xdg_home_folder('LOCAL_BIN_DIR', '.local/bin') // provides a way to test by setting an env variable
944948
}
@@ -982,6 +986,7 @@ pub fn temp_dir() string {
982986

983987
// vtmp_dir returns the path to a folder, that is writable to V programs, *and* specific to the OS user.
984988
// It can be overridden by setting the env variable `VTMP`.
989+
// Note: This function ensures that the returned directory exists and panics if directory creation fails.
985990
pub fn vtmp_dir() string {
986991
mut vtmp := getenv('VTMP')
987992
if vtmp.len > 0 {

0 commit comments

Comments
 (0)