Skip to content

Use LOCALAPPDATA for system cache on windows #2297

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

Merged
merged 4 commits into from
Jan 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/system_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ class SystemCache {
if (Platform.environment.containsKey('PUB_CACHE')) {
return Platform.environment['PUB_CACHE'];
} else if (Platform.isWindows) {
// %LOCALAPPDATA% is preferred as the cache location over %APPDATA%, because the latter is synchronised between
// devices when the user roams between them, whereas the former is not.
// The default cache dir used to be in %APPDATA%, so to avoid breaking old installs,
// we use the old dir in %APPDATA% if it exists. Else, we use the new default location
// in %LOCALAPPDATA%.
var appData = Platform.environment['APPDATA'];
return p.join(appData, 'Pub', 'Cache');
var appDataCacheDir = p.join(appData, 'Pub', 'Cache');
if (dirExists(appDataCacheDir)) {
return appDataCacheDir;
}
var localAppData = Platform.environment['LOCALAPPDATA'];
return p.join(localAppData, 'Pub', 'Cache');
} else {
return '${Platform.environment['HOME']}/.pub-cache';
}
Expand Down