Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#27064: system: use %LOCALAPPDATA% as default da…
Browse files Browse the repository at this point in the history
…tadir on windows

84900ac doc: add release-notes-27064.md (Matthew Zipkin)
855dd8d system: use %LOCALAPPDATA% as default datadir on windows (Matthew Zipkin)

Pull request description:

  Closes bitcoin/bitcoin#2391

  This PR changes the default datadir location on Windows from `C:\Users\Username\AppData\Roaming\Bitcoin` to `C:\Users\Username\AppData\Local\Bitcoin`. This change only applies to fresh installs. To preserve backwards compatibility, on startup we check for the existence of `C:\Users\Username\AppData\Roaming\Bitcoin\chainstate` and if it is there, we continue using the "Roaming" directory as the default datadir location.

  [Note that in Windows 11 this change may be moot:](https://learn.microsoft.com/en-us/uwp/api/windows.storage.applicationdata.roamingfolder?view=winrt-22621)

  > Roaming data and settings is no longer supported as of Windows 11. The recommended replacement is [Azure App Service](https://learn.microsoft.com/en-us/azure/app-service/). Azure App Service is widely supported, well documented, reliable, and supports cross-platform/cross-ecosystem scenarios such as iOS, Android and web. Settings stored here no longer roam (as of Windows 11), but the settings store is still available.

ACKs for top commit:
  achow101:
    ACK 84900ac
  BenWestgate:
    crACK bitcoin/bitcoin@84900ac
  hebasto:
    re-ACK 84900ac, only addressed feedback since my recent [review](bitcoin/bitcoin#27064 (review)).

Tree-SHA512: 807c6e89571287e2c8f4934229aec91ef28e7d0a675234acf1b7d085c24c7b73a08b6e345fbfc9038e6239187b6b69c08490ddaa1c057de5ea975c4a000bba42
  • Loading branch information
achow101 committed May 23, 2024
2 parents 867f6af + 84900ac commit 915d727
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/bitcoin-conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The `includeconf=<file>` option in the `bitcoin.conf` file can be used to includ

Operating System | Data Directory | Example Path
-- | -- | --
Windows | `%APPDATA%\Bitcoin\` | `C:\Users\username\AppData\Roaming\Bitcoin\bitcoin.conf`
Windows | `%LOCALAPPDATA%\Bitcoin\` | `C:\Users\username\AppData\Local\Bitcoin\bitcoin.conf`
Linux | `$HOME/.bitcoin/` | `/home/username/.bitcoin/bitcoin.conf`
macOS | `$HOME/Library/Application Support/Bitcoin/` | `/Users/username/Library/Application Support/Bitcoin/bitcoin.conf`

Expand Down
2 changes: 1 addition & 1 deletion doc/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Platform | Data directory path
---------|--------------------
Linux | `$HOME/.bitcoin/`
macOS | `$HOME/Library/Application Support/Bitcoin/`
Windows | `%APPDATA%\Bitcoin\` <sup>[\[1\]](#note1)</sup>
Windows | `%LOCALAPPDATA%\Bitcoin\` <sup>[\[1\]](#note1)</sup>

2. A custom data directory path can be specified with the `-datadir` option.

Expand Down
2 changes: 1 addition & 1 deletion doc/managing-wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ By default, wallets are created in the `wallets` folder of the data directory, w
| Operating System | Default wallet directory |
| -----------------|:------------------------------------------------------------|
| Linux | `/home/<user>/.bitcoin/wallets` |
| Windows | `C:\Users\<user>\AppData\Roaming\Bitcoin\wallets` |
| Windows | `C:\Users\<user>\AppData\Local\Bitcoin\wallets` |
| macOS | `/Users/<user>/Library/Application Support/Bitcoin/wallets` |

### 1.2 Encrypting the Wallet
Expand Down
7 changes: 7 additions & 0 deletions doc/release-notes/release-notes-27064.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Files
-----

The default data directory on Windows has been moved from `C:\Users\Username\AppData\Roaming\Bitcoin`
to `C:\Users\Username\AppData\Local\Bitcoin`. Bitcoin Core will check the existence
of the old directory first and continue to use that directory for backwards
compatibility if it is present.
11 changes: 9 additions & 2 deletions src/common/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,19 @@ bool HasTestOption(const ArgsManager& args, const std::string& test_option)

fs::path GetDefaultDataDir()
{
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
// Windows:
// old: C:\Users\Username\AppData\Roaming\Bitcoin
// new: C:\Users\Username\AppData\Local\Bitcoin
// macOS: ~/Library/Application Support/Bitcoin
// Unix-like: ~/.bitcoin
#ifdef WIN32
// Windows
return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
// Check for existence of datadir in old location and keep it there
fs::path legacy_path = GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
if (fs::exists(legacy_path)) return legacy_path;

// Otherwise, fresh installs can start in the new, "proper" location
return GetSpecialFolderPath(CSIDL_LOCAL_APPDATA) / "Bitcoin";
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
Expand Down

0 comments on commit 915d727

Please sign in to comment.