Skip to content

Commit 82e60a3

Browse files
Jesse-Bakkerjonasfj
authored andcommitted
Use LOCALAPPDATA for system cache on windows (#2297)
Use `%LOCALAPPDATA%` for `.pub-cache` on windows if `.pub-cache` doesn't already existing in `%APPDATA%`. Using `%LOCALAPPDATA%` is better because it's not copied when users roam between devices.
1 parent ceaa86f commit 82e60a3

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lib/src/system_cache.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,18 @@ class SystemCache {
3535
if (Platform.environment.containsKey('PUB_CACHE')) {
3636
return Platform.environment['PUB_CACHE'];
3737
} else if (Platform.isWindows) {
38+
// %LOCALAPPDATA% is preferred as the cache location over %APPDATA%, because the latter is synchronised between
39+
// devices when the user roams between them, whereas the former is not.
40+
// The default cache dir used to be in %APPDATA%, so to avoid breaking old installs,
41+
// we use the old dir in %APPDATA% if it exists. Else, we use the new default location
42+
// in %LOCALAPPDATA%.
3843
var appData = Platform.environment['APPDATA'];
39-
return p.join(appData, 'Pub', 'Cache');
44+
var appDataCacheDir = p.join(appData, 'Pub', 'Cache');
45+
if (dirExists(appDataCacheDir)) {
46+
return appDataCacheDir;
47+
}
48+
var localAppData = Platform.environment['LOCALAPPDATA'];
49+
return p.join(localAppData, 'Pub', 'Cache');
4050
} else {
4151
return '${Platform.environment['HOME']}/.pub-cache';
4252
}

0 commit comments

Comments
 (0)