Fossil

Check-in [8388a468]
Login

Check-in [8388a468]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Further refinement to the configuration database locator algorithm to only use the XDG name if the ~/.config directory exists.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8388a4680f9e2db4dfe281cbe98630decfe05b0a61809810b4e780c1c11e7e4f
User & Date: drh 2020-04-19 15:04:11
Context
2020-04-19
15:20
Improved documentation of the latest configuration database locator algorithm. No code changes. ... (check-in: 9cb8194d user: drh tags: trunk)
15:04
Further refinement to the configuration database locator algorithm to only use the XDG name if the ~/.config directory exists. ... (check-in: 8388a468 user: drh tags: trunk)
14:40
Update the configuration-database location documentation to reflect enhancements to the "fossil info" command. ... (check-in: b980ede0 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/db.c.
1468
1469
1470
1471
1472
1473
1474
1475
1476



1477





1478
1479
1480
1481
1482
1483
1484
  if( zHome==0 ){
    if( isOptional ) return 0;
    fossil_panic("cannot locate home directory - please set one of the "
                 "FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment "
                 "variables");
  }

  /* Step 5: Otherwise -> $HOME/.config/fossil.db
  */



  return mprintf("%s/.config/fossil.db", zHome);





#endif /* unix */
}

/*
** Open the configuration database.  Create the database anew if
** it does not already exist.
**







|

>
>
>
|
>
>
>
>
>







1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
  if( zHome==0 ){
    if( isOptional ) return 0;
    fossil_panic("cannot locate home directory - please set one of the "
                 "FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment "
                 "variables");
  }

  /* Step 5: If $HOME/.config is a directory -> $HOME/.config/fossil.db
  */
  zXdgHome = mprintf("%s/.config", zHome);
  if( file_isdir(zXdgHome, ExtFILE)==1 ){
    fossil_free(zXdgHome);
    return mprintf("%s/.config/fossil.db", zHome);
  }

  /* Step 6: Otherwise -> $HOME/.fossil
  */
  return mprintf("%s/.fossil", zHome);
#endif /* unix */
}

/*
** Open the configuration database.  Create the database anew if
** it does not already exist.
**
Changes to www/tech_overview.wiki.
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

  *  if environment variable FOSSIL_HOME exists → $FOSSIL_HOME/.fossil
  *  if environment variable HOME exists and
     if file $HOME/fossil exists → $HOME/.fossil
  *  if environment variable XDG_CONFIG_HOME exists
     → $XDG_CONFIG_HOME/fossil.db
  *  if environment variable HOME does not exist &rarr; <i>ERROR</i>

  *  Otherwise $HOME/.config/fossil.db

Another way of thinking of this algorithm is the following:

  *  Use "$FOSSIL_HOME/.fossil" if the FOSSIL_HOME variable is defined
  *  Use the traditional unix configuration file name of
     "$HOME/.fossil" if HOME is defined and if that file exists.
  *  Use an XDG compatible name otherwise.

This algorithm is complex due to the need for historical compatibility.
Originally, the database was always named "$HOME/.fossil".  Then support
for the FOSSIL_HOME environment variable as added.  Later, support for the
[https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames]
was added.  Each of these changes needed to continue to support legacy installs.

On Windows, the configuration database is the first of the following
for which the corresponding environment variables exist:








>
|




|
|
|


|







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

  *  if environment variable FOSSIL_HOME exists &rarr; $FOSSIL_HOME/.fossil
  *  if environment variable HOME exists and
     if file $HOME/fossil exists &rarr; $HOME/.fossil
  *  if environment variable XDG_CONFIG_HOME exists
     &rarr; $XDG_CONFIG_HOME/fossil.db
  *  if environment variable HOME does not exist &rarr; <i>ERROR</i>
  *  if a directory named $HOME/.config exists &rarr; $HOME/.config/fossil.db
  *  Otherwise $HOME/.fossil

Another way of thinking of this algorithm is the following:

  *  Use "$FOSSIL_HOME/.fossil" if the FOSSIL_HOME variable is defined
  *  Use the XDG-compatible name (~/.config/fossil.db) on XDG systems
     if the ~/.fossil file does not already exist
  *  Otherwise, use the traditional unix name of "~/.fossil"

This algorithm is complex due to the need for historical compatibility.
Originally, the database was always just "$HOME/.fossil".  Then support
for the FOSSIL_HOME environment variable as added.  Later, support for the
[https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html|XDG-compatible configation filenames]
was added.  Each of these changes needed to continue to support legacy installs.

On Windows, the configuration database is the first of the following
for which the corresponding environment variables exist: