Fossil SCM
Further refinement to the configuration database locator algorithm to only use the XDG name if the ~/.config directory exists.
Commit
8388a4680f9e2db4dfe281cbe98630decfe05b0a61809810b4e780c1c11e7e4f
Parent
b980ede08b0b114…
2 files changed
+10
-2
+6
-5
M
src/db.c
+10
-2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1470,13 +1470,21 @@ | ||
| 1470 | 1470 | fossil_panic("cannot locate home directory - please set one of the " |
| 1471 | 1471 | "FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment " |
| 1472 | 1472 | "variables"); |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 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 | |
| 1476 | 1484 | */ |
| 1477 | - return mprintf("%s/.config/fossil.db", zHome); | |
| 1485 | + return mprintf("%s/.fossil", zHome); | |
| 1478 | 1486 | #endif /* unix */ |
| 1479 | 1487 | } |
| 1480 | 1488 | |
| 1481 | 1489 | /* |
| 1482 | 1490 | ** Open the configuration database. Create the database anew if |
| 1483 | 1491 |
| --- 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 |
+6
-5
| --- www/tech_overview.wiki | ||
| +++ www/tech_overview.wiki | ||
| @@ -137,21 +137,22 @@ | ||
| 137 | 137 | * if environment variable HOME exists and |
| 138 | 138 | if file $HOME/fossil exists → $HOME/.fossil |
| 139 | 139 | * if environment variable XDG_CONFIG_HOME exists |
| 140 | 140 | → $XDG_CONFIG_HOME/fossil.db |
| 141 | 141 | * if environment variable HOME does not exist → <i>ERROR</i> |
| 142 | - * Otherwise $HOME/.config/fossil.db | |
| 142 | + * if a directory named $HOME/.config exists → $HOME/.config/fossil.db | |
| 143 | + * Otherwise $HOME/.fossil | |
| 143 | 144 | |
| 144 | 145 | Another way of thinking of this algorithm is the following: |
| 145 | 146 | |
| 146 | 147 | * 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" | |
| 150 | 151 | |
| 151 | 152 | 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 | |
| 153 | 154 | for the FOSSIL_HOME environment variable as added. Later, support for the |
| 154 | 155 | [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames] |
| 155 | 156 | was added. Each of these changes needed to continue to support legacy installs. |
| 156 | 157 | |
| 157 | 158 | On Windows, the configuration database is the first of the following |
| 158 | 159 |
| --- 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 → $HOME/.fossil |
| 139 | * if environment variable XDG_CONFIG_HOME exists |
| 140 | → $XDG_CONFIG_HOME/fossil.db |
| 141 | * if environment variable HOME does not exist → <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 → $HOME/.fossil |
| 139 | * if environment variable XDG_CONFIG_HOME exists |
| 140 | → $XDG_CONFIG_HOME/fossil.db |
| 141 | * if environment variable HOME does not exist → <i>ERROR</i> |
| 142 | * if a directory named $HOME/.config exists → $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 |