From: Lennart Poettering Date: Mon, 20 Apr 2026 09:41:53 +0000 (+0200) Subject: sd-path: expose XDG 'projects' user dir X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4256a9b31361c5d41b4eb3290cca78a71245abe;p=thirdparty%2Fsystemd.git sd-path: expose XDG 'projects' user dir As per: https://blog.tenstral.net/2026/04/hello-projects-directory.html --- diff --git a/man/sd_path_lookup.xml b/man/sd_path_lookup.xml index 9190e6b00a4..07592e71ceb 100644 --- a/man/sd_path_lookup.xml +++ b/man/sd_path_lookup.xml @@ -68,6 +68,7 @@ SD_PATH_USER_PUBLIC, SD_PATH_USER_TEMPLATES, SD_PATH_USER_DESKTOP, + SD_PATH_USER_PROJECTS, SD_PATH_SEARCH_BINARIES, SD_PATH_SEARCH_BINARIES_DEFAULT, diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index e009a71bea0..eebcd20b6f9 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -282,6 +282,9 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { case SD_PATH_USER_DESKTOP: return from_xdg_user_dir("XDG_DESKTOP_DIR", buffer, ret); + case SD_PATH_USER_PROJECTS: + return from_xdg_user_dir("XDG_PROJECTS_DIR", buffer, ret); + case SD_PATH_SYSTEMD_UTIL: *ret = PREFIX_NOSLASH "/lib/systemd"; return 0; diff --git a/src/path/path-tool.c b/src/path/path-tool.c index 797a7d06af8..1920ff8d600 100644 --- a/src/path/path-tool.c +++ b/src/path/path-tool.c @@ -61,6 +61,7 @@ static const char* const path_table[_SD_PATH_MAX] = { [SD_PATH_USER_PUBLIC] = "user-public", [SD_PATH_USER_TEMPLATES] = "user-templates", [SD_PATH_USER_DESKTOP] = "user-desktop", + [SD_PATH_USER_PROJECTS] = "user-projects", [SD_PATH_SEARCH_BINARIES] = "search-binaries", [SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default", diff --git a/src/systemd/sd-path.h b/src/systemd/sd-path.h index 2718cf82664..299fb20adea 100644 --- a/src/systemd/sd-path.h +++ b/src/systemd/sd-path.h @@ -132,6 +132,8 @@ __extension__ enum { SD_PATH_USER_CREDENTIAL_STORE_ENCRYPTED, SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED, + SD_PATH_USER_PROJECTS, + _SD_PATH_MAX, _SD_PATH_INVALID = UINT64_MAX }; diff --git a/test/units/TEST-74-AUX-UTILS.path.sh b/test/units/TEST-74-AUX-UTILS.path.sh index 4547f53e24d..14f7ef8ec06 100755 --- a/test/units/TEST-74-AUX-UTILS.path.sh +++ b/test/units/TEST-74-AUX-UTILS.path.sh @@ -39,6 +39,7 @@ XDG_DOCUMENTS_DIR="$HOME/top/secret/documents" XDG_MUSIC_DIR="/tmp/vaporwave" XDG_PICTURES_DIR="$HOME/Pictures" XDG_VIDEOS_DIR="$HOME/🤔" +XDG_PROJECTS_DIR="$HOME/my-projects" EOF systemd-path --help @@ -66,12 +67,13 @@ assert_eq "$(systemd-path user-pictures)" "/root/Pictures" assert_eq "$(systemd-path user-public)" "/root/cat-pictures" assert_eq "$(systemd-path user-templates)" "/templates" assert_eq "$(systemd-path user-videos)" "/root/🤔" +assert_eq "$(systemd-path user-projects)" "/root/my-projects" # Remove the user-dirs.dir file and check the defaults rm -fv "$USER_DIRS_CONF" [[ ! -e "$USER_DIRS_CONF" ]] assert_eq "$(systemd-path user-desktop)" "/root/Desktop" -for dir in "" documents download music pictures public templates videos; do +for dir in "" documents download music pictures public templates videos projects; do assert_eq "$(systemd-path "user${dir:+-$dir}")" "/root" done