@@ -23,6 +23,7 @@ import 'source/hosted.dart';
2323import 'source/path.dart' ;
2424import 'source/sdk.dart' ;
2525import 'source/unknown.dart' ;
26+ import 'utils.dart' ;
2627
2728/// The system-wide cache of downloaded packages.
2829///
@@ -41,21 +42,26 @@ class SystemCache {
4142 if (Platform .environment.containsKey ('PUB_CACHE' )) {
4243 return Platform .environment['PUB_CACHE' ]! ;
4344 } else if (Platform .isWindows) {
44- // %LOCALAPPDATA% is preferred as the cache location over %APPDATA%, because the latter is synchronised between
45- // devices when the user roams between them, whereas the former is not.
46- // The default cache dir used to be in %APPDATA%, so to avoid breaking old installs,
47- // we use the old dir in %APPDATA% if it exists. Else, we use the new default location
48- // in %LOCALAPPDATA%.
49- // TODO(sigurdm): handle missing APPDATA.
50- var appData = Platform .environment['APPDATA' ]! ;
51- var appDataCacheDir = p.join (appData, 'Pub' , 'Cache' );
52- if (dirExists (appDataCacheDir)) {
53- return appDataCacheDir;
45+ // %LOCALAPPDATA% is used as the cache location over %APPDATA%, because
46+ // the latter is synchronised between devices when the user roams between
47+ // them, whereas the former is not.
48+ final localAppData = Platform .environment['LOCALAPPDATA' ];
49+ if (localAppData == null ) {
50+ dataError ('''
51+ Could not find the pub cache. No `LOCALAPPDATA` environment variable exists.
52+ Consider setting the `PUB_CACHE` variable manually.
53+ ''' );
5454 }
55- var localAppData = Platform .environment['LOCALAPPDATA' ]! ;
5655 return p.join (localAppData, 'Pub' , 'Cache' );
5756 } else {
58- return '${Platform .environment ['HOME' ]}/.pub-cache' ;
57+ final home = Platform .environment['HOME' ];
58+ if (home == null ) {
59+ dataError ('''
60+ Could not find the pub cache. No `HOME` environment variable exists.
61+ Consider setting the `PUB_CACHE` variable manually.
62+ ''' );
63+ }
64+ return p.join (home, '.pub-cache' );
5965 }
6066 })();
6167
0 commit comments