Fossil SCM

Further refinement to the configuration database locator algorithm to only use the XDG name if the ~/.config directory exists.

drh 2020-04-19 15:04 trunk
Commit 8388a4680f9e2db4dfe281cbe98630decfe05b0a61809810b4e780c1c11e7e4f
2 files changed +10 -2 +6 -5
+10 -2
--- src/db.c
+++ src/db.c
@@ -1470,13 +1470,21 @@
14701470
fossil_panic("cannot locate home directory - please set one of the "
14711471
"FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment "
14721472
"variables");
14731473
}
14741474
1475
- /* Step 5: Otherwise -> $HOME/.config/fossil.db
1475
+ /* Step 5: If $HOME/.config is a directory -> $HOME/.config/fossil.db
1476
+ */
1477
+ zXdgHome = mprintf("%s/.config", zHome);
1478
+ if( file_isdir(zXdgHome, ExtFILE)==1 ){
1479
+ fossil_free(zXdgHome);
1480
+ return mprintf("%s/.config/fossil.db", zHome);
1481
+ }
1482
+
1483
+ /* Step 6: Otherwise -> $HOME/.fossil
14761484
*/
1477
- return mprintf("%s/.config/fossil.db", zHome);
1485
+ return mprintf("%s/.fossil", zHome);
14781486
#endif /* unix */
14791487
}
14801488
14811489
/*
14821490
** Open the configuration database. Create the database anew if
14831491
--- src/db.c
+++ src/db.c
@@ -1470,13 +1470,21 @@
1470 fossil_panic("cannot locate home directory - please set one of the "
1471 "FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment "
1472 "variables");
1473 }
1474
1475 /* Step 5: Otherwise -> $HOME/.config/fossil.db
 
 
 
 
 
 
 
 
1476 */
1477 return mprintf("%s/.config/fossil.db", zHome);
1478 #endif /* unix */
1479 }
1480
1481 /*
1482 ** Open the configuration database. Create the database anew if
1483
--- src/db.c
+++ src/db.c
@@ -1470,13 +1470,21 @@
1470 fossil_panic("cannot locate home directory - please set one of the "
1471 "FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment "
1472 "variables");
1473 }
1474
1475 /* Step 5: If $HOME/.config is a directory -> $HOME/.config/fossil.db
1476 */
1477 zXdgHome = mprintf("%s/.config", zHome);
1478 if( file_isdir(zXdgHome, ExtFILE)==1 ){
1479 fossil_free(zXdgHome);
1480 return mprintf("%s/.config/fossil.db", zHome);
1481 }
1482
1483 /* Step 6: Otherwise -> $HOME/.fossil
1484 */
1485 return mprintf("%s/.fossil", zHome);
1486 #endif /* unix */
1487 }
1488
1489 /*
1490 ** Open the configuration database. Create the database anew if
1491
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -137,21 +137,22 @@
137137
* if environment variable HOME exists and
138138
if file $HOME/fossil exists → $HOME/.fossil
139139
* if environment variable XDG_CONFIG_HOME exists
140140
→ $XDG_CONFIG_HOME/fossil.db
141141
* if environment variable HOME does not exist &rarr; <i>ERROR</i>
142
- * Otherwise $HOME/.config/fossil.db
142
+ * if a directory named $HOME/.config exists &rarr; $HOME/.config/fossil.db
143
+ * Otherwise $HOME/.fossil
143144
144145
Another way of thinking of this algorithm is the following:
145146
146147
* Use "$FOSSIL_HOME/.fossil" if the FOSSIL_HOME variable is defined
147
- * Use the traditional unix configuration file name of
148
- "$HOME/.fossil" if HOME is defined and if that file exists.
149
- * Use an XDG compatible name otherwise.
148
+ * Use the XDG-compatible name (~/.config/fossil.db) on XDG systems
149
+ if the ~/.fossil file does not already exist
150
+ * Otherwise, use the traditional unix name of "~/.fossil"
150151
151152
This algorithm is complex due to the need for historical compatibility.
152
-Originally, the database was always named "$HOME/.fossil". Then support
153
+Originally, the database was always just "$HOME/.fossil". Then support
153154
for the FOSSIL_HOME environment variable as added. Later, support for the
154155
[https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames]
155156
was added. Each of these changes needed to continue to support legacy installs.
156157
157158
On Windows, the configuration database is the first of the following
158159
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -137,21 +137,22 @@
137 * if environment variable HOME exists and
138 if file $HOME/fossil exists &rarr; $HOME/.fossil
139 * if environment variable XDG_CONFIG_HOME exists
140 &rarr; $XDG_CONFIG_HOME/fossil.db
141 * if environment variable HOME does not exist &rarr; <i>ERROR</i>
142 * Otherwise $HOME/.config/fossil.db
 
143
144 Another way of thinking of this algorithm is the following:
145
146 * Use "$FOSSIL_HOME/.fossil" if the FOSSIL_HOME variable is defined
147 * Use the traditional unix configuration file name of
148 "$HOME/.fossil" if HOME is defined and if that file exists.
149 * Use an XDG compatible name otherwise.
150
151 This algorithm is complex due to the need for historical compatibility.
152 Originally, the database was always named "$HOME/.fossil". Then support
153 for the FOSSIL_HOME environment variable as added. Later, support for the
154 [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames]
155 was added. Each of these changes needed to continue to support legacy installs.
156
157 On Windows, the configuration database is the first of the following
158
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -137,21 +137,22 @@
137 * if environment variable HOME exists and
138 if file $HOME/fossil exists &rarr; $HOME/.fossil
139 * if environment variable XDG_CONFIG_HOME exists
140 &rarr; $XDG_CONFIG_HOME/fossil.db
141 * if environment variable HOME does not exist &rarr; <i>ERROR</i>
142 * if a directory named $HOME/.config exists &rarr; $HOME/.config/fossil.db
143 * Otherwise $HOME/.fossil
144
145 Another way of thinking of this algorithm is the following:
146
147 * Use "$FOSSIL_HOME/.fossil" if the FOSSIL_HOME variable is defined
148 * Use the XDG-compatible name (~/.config/fossil.db) on XDG systems
149 if the ~/.fossil file does not already exist
150 * Otherwise, use the traditional unix name of "~/.fossil"
151
152 This algorithm is complex due to the need for historical compatibility.
153 Originally, the database was always just "$HOME/.fossil". Then support
154 for the FOSSIL_HOME environment variable as added. Later, support for the
155 [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames]
156 was added. Each of these changes needed to continue to support legacy installs.
157
158 On Windows, the configuration database is the first of the following
159

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button