From: stephan Date: Mon, 30 Jun 2025 11:46:10 +0000 (+0000) Subject: Preliminary refactoring of the XDG_CONFIG_HOME support to support the pending additio... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbcf035954589f550620a87077c057973ba1d176;p=thirdparty%2Fsqlite.git Preliminary refactoring of the XDG_CONFIG_HOME support to support the pending addition of other XDG-configurable options. In response to [forum:31db1a23f9 | forum post 31db1a23f9]. FossilOrigin-Name: 69b9244e3ad95edae38d8e66cedafbc1d7724ae0dd72eeee0fdbff913983598e --- diff --git a/manifest b/manifest index 69225deb3f..1ff571dcf0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sAPI\sdoc\stypo\sfixes\sfrom\sbrickviking. -D 2025-06-30T11:00:59.442 +C Preliminary\srefactoring\sof\sthe\sXDG_CONFIG_HOME\ssupport\sto\ssupport\sthe\spending\saddition\sof\sother\sXDG-configurable\soptions.\sIn\sresponse\sto\s[forum:31db1a23f9\s|\sforum\spost\s31db1a23f9]. +D 2025-06-30T11:46:10.395 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -786,7 +786,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c d40fe18d7c2fd0339f5846ffcf7d6809866e380acdf14c76fb2af87e9fe13f64 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 882d739e0d5e6c7a8b46a3cca3ada37fe1a56301f1360d6b141312c666bbe482 -F src/shell.c.in 4f14a1f5196b6006abc8e73cc8fd6c1a62cf940396f8ba909d6711f35f074bb6 +F src/shell.c.in 98cc5a8ef982e9c60e0d8146ed8c38774a0f80f23c104a115c27f05893d3641d F src/sqlite.h.in 5c54f2461a1ea529bab8499148a2b238e2d4bb571d59e8ea5322d0c190abb693 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 0bfd049bb2088cc44c2ad54f2079d1c6e43091a4e1ce8868779b75f6c1484f1e @@ -2208,8 +2208,11 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c7cf9dcb69ce558ba6b81b2787f92ed7383e37f08b199faeb14f7adb4e494532 -R d7a5649d84482afb1911b4bf92ab7f49 +P b48d95191662e09659b5b55ae65cd462c9e1700c4f92dd9d40b59548f0797c02 +R 6309a1fd152193cda47202f25b8c3c35 +T *branch * shell-xdg-vars +T *sym-shell-xdg-vars * +T -sym-trunk * Cancelled\sby\sbranch. U stephan -Z d71a9678ab9d14d6cf50fe9f605c6dd8 +Z 195b94022bc466347bd2a5713b9a2796 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d0d4e9bef5..1bc3ddd926 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b48d95191662e09659b5b55ae65cd462c9e1700c4f92dd9d40b59548f0797c02 +69b9244e3ad95edae38d8e66cedafbc1d7724ae0dd72eeee0fdbff913983598e diff --git a/src/shell.c.in b/src/shell.c.in index 33dd30697d..6302a9a17c 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12759,30 +12759,34 @@ static char *find_home_dir(int clearFlag){ } /* -** On non-Windows platforms, look for $XDG_CONFIG_HOME. -** If ${XDG_CONFIG_HOME}/sqlite3/sqliterc is found, return -** the path to it. If there is no $(XDG_CONFIG_HOME) then -** look for $(HOME)/.config/sqlite3/sqliterc and if found -** return that. If none of these are found, return 0. +** On non-Windows platforms, look for $zEnvVar, which must be the name +** of an XDG_... environment variable. If ${zEnvVar}/${zBaseName} is +** found, return the path to it. If ${zEnvVar} is not set then look +** for ${HOME}/${zSubdir}/${zBaseName} and if found return that. If +** none of these are found, return 0. +** +** Both zSubdir and zBaseName may contain subdirectory parts. zSubdir +** will conventionally be ".config" or ".local". ** ** The string returned is obtained from sqlite3_malloc() and ** should be freed by the caller. */ -static char *find_xdg_config(void){ +static char *find_xdg_file(const char *zEnvVar, const char *zSubdir, + const char *zBaseName){ #if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \ || defined(__RTP__) || defined(_WRS_KERNEL) return 0; #else char *zConfig = 0; - const char *zXdgHome; + const char *zXdgDir; - zXdgHome = getenv("XDG_CONFIG_HOME"); - if( zXdgHome==0 ){ + zXdgDir = getenv(zEnvVar); + if( zXdgDir==0 ){ const char *zHome = getenv("HOME"); if( zHome==0 ) return 0; - zConfig = sqlite3_mprintf("%s/.config/sqlite3/sqliterc", zHome); + zConfig = sqlite3_mprintf("%s/%s/%s", zHome, zSubdir, zBaseName); }else{ - zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome); + zConfig = sqlite3_mprintf("%s/%s", zXdgDir, zBaseName); } shell_check_oom(zConfig); if( access(zConfig,0)!=0 ){ @@ -12795,7 +12799,7 @@ static char *find_xdg_config(void){ /* ** Read input from the file given by sqliterc_override. Or if that -** parameter is NULL, take input from the first of find_xdg_config() +** parameter is NULL, take input from the first of find_xdg_file() ** or ~/.sqliterc which is found. ** ** Returns the number of errors. @@ -12811,7 +12815,8 @@ static void process_sqliterc( int savedLineno = p->lineno; if( sqliterc == NULL ){ - sqliterc = zBuf = find_xdg_config(); + sqliterc = zBuf = find_xdg_file("XDG_CONFIG_HOME", + ".config", "sqlite3/sqliterc"); } if( sqliterc == NULL ){ home_dir = find_home_dir(0);