Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system: use %LOCALAPPDATA% as default datadir on windows #27064

Merged
merged 2 commits into from
May 23, 2024

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Feb 8, 2023

Closes #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:

Roaming data and settings is no longer supported as of Windows 11. The recommended replacement is 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 8, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK hebasto, achow101, BenWestgate

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@hebasto
Copy link
Member

hebasto commented Feb 8, 2023

cc @sipsorcery

@hebasto hebasto added the Windows label Feb 8, 2023
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pinheadmz
Copy link
Member Author

Would this change need a release-notes-27064.md file? It is kinda changing a configuration model

@pinheadmz
Copy link
Member Author

Push to 60cd07b:

  • rebase on master
  • add PR release note
  • change how we detect "old" directory use from looking for blocks/ to looking for chainstate/

@hebasto
Copy link
Member

hebasto commented May 22, 2023

Concept ACK.

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 / "chainstate"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the PR description:

we check for the existence of C:\Users\Username\AppData\Roaming\Bitcoin\blocks

?

Copy link
Member Author

@pinheadmz pinheadmz May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch thanks. (fixed) First draft of this PR did check for blocks directory but of course that is unreliable because it could be customized by the user.

@hebasto
Copy link
Member

hebasto commented May 23, 2023

This change ignores non-main network data. I'm OK with that. But it seems worth mentioning in the docs.

@pinheadmz
Copy link
Member Author

This change ignores non-main network data.

Ah I see, because I'm checking for Bitcoin\chainstate specifically but if a user only ever used signet, there would be a nested signet directory in there too. Is there anything else I can check for that always gets written to that root? Or maybe just check if Bitcoin\ is empty at all?

I'm OK with that. But it seems worth mentioning in the docs.

Sure but I feel like that's not super clean either.

@luke-jr
Copy link
Member

luke-jr commented Jun 22, 2023

Why would we prefer local over roaming explicitly?

@pinheadmz
Copy link
Member Author

Why would we prefer local over roaming explicitly?

From https://www.makeuseof.com/tag/appdata-roaming-vs-local/

In the end, Roaming and Local are functionally identical for a home PC running Windows. In a domain environment, data in the Roaming folder will stay with a user's profile if they move to a different computer.

In other words, 500 GB of blockchain data would be copied to a user's remote workstation as they move around. Roaming is just supposed to be for small files like profile preferences, etc. Not big data stores.

More discussion in #2391

@achow101
Copy link
Member

on startup we check for the existence of C:\Users\Username\AppData\Roaming\Bitcoin\chainstate

I think we should check for existence of Roaming\Bitcoin rather than any subdirectory. This would not only catch non-mainnet datadirs, but also avoid compatibility issues with users who are looking at older instructions. For example, it's conceivable that a user following a guide that tells them to use Roaming would create Roaming\Bitcoin\bitcoin.conf before their first startup, and thus expect any settings in that conf file to be picked up. Currently, that would not be the case.

@pinheadmz
Copy link
Member Author

I think we should check for existence of Roaming\Bitcoin rather than any subdirectory.

revised, rebased on master and pushed thanks.

I tested this "in production" on my windows laptop but found writing a functional test to be impossible. I thought I could model a test after @ryanofsky commit here: 8d777c0

...but for default datadir we use windows' SHGetSpecialFolderPathW with CSIDL_APPDATA which override environment variables: https://learn.microsoft.com/en-us/windows/win32/shell/csidl#remarks

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 5, 2024

Could rebase for fresh CI, if still relevant?

@achow101
Copy link
Member

crACK c941712

Have not yet tested on a Windows machine.

@DrahtBot DrahtBot requested a review from hebasto April 15, 2024 21:37
@achow101 achow101 removed their request for review April 15, 2024 21:37
@pinheadmz
Copy link
Member Author

Could rebase for fresh CI, if still relevant?

rebased on master

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c59b1e4, tested on Windows 11 Pro 23H2.

@@ -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 | `%APPDATA%\Bitcoin\` | `C:\Users\username\AppData\Local\Bitcoin\bitcoin.conf`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Windows | `%APPDATA%\Bitcoin\` | `C:\Users\username\AppData\Local\Bitcoin\bitcoin.conf`
Windows | `%LOCALAPPDATA%\Bitcoin\` | `C:\Users\username\AppData\Local\Bitcoin\bitcoin.conf`

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
compatability if it is present.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo:

Suggested change
compatability if it is present.
compatibility if it is present.

Comment on lines 708 to 709
if (fs::exists(legacy_path))
return legacy_path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could add curly braces or put in a single line?

@DrahtBot DrahtBot requested a review from achow101 April 29, 2024 14:43
@pinheadmz
Copy link
Member Author

@hebasto thanks for the review, I addressed your comments

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 84900ac, only addressed feedback since my recent review.

@achow101
Copy link
Member

achow101 commented May 1, 2024

ACK 84900ac

Tested on Windows. %APPDATA%/Bitcoin continues to be used if it exists, %LOCALAPPDATA% if not.

@BenWestgate
Copy link
Contributor

crACK 84900ac

Have not tested on a Windows machine.

@achow101 achow101 merged commit 915d727 into bitcoin:master May 23, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use AppData\Local instead of AppData\Roaming
7 participants