Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove if-else branches introduced in [1], fixing crash bug when
`$HOME/.dart/` does not exists.

[1]: https://dart-review.googlesource.com/c/sdk/+/168947

Fixed: 44027
Change-Id: Ic178ebf8eb04ac34c1574269b5d7191a5e514460
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170088
Auto-Submit: Jonas Jensen <jonasfj@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
  • Loading branch information
jonasfj authored and commit-bot@chromium.org committed Nov 2, 2020
1 parent 416cfa7 commit 5918aa8
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions pkg/dartdev/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,46 @@ Analytics createAnalyticsInstance(bool disableAnalytics) {
if (Platform.environment['_DARTDEV_LOG_ANALYTICS'] != null) {
// Used for testing what analytics messages are sent.
_instance = _LoggingAnalytics();
} else if (disableAnalytics) {
return _instance;
}

if (disableAnalytics) {
// Dartdev tests pass a hidden 'disable-dartdev-analytics' flag which is
// handled here.
// Also, stdout.hasTerminal is checked, if there is no terminal we infer that
// a machine is running dartdev so we return analytics shouldn't be set.
_instance = DisabledAnalytics(_trackingId, _appName);
} else {
var settingsDir = getDartStorageDirectory();
if (settingsDir == null) {
// Some systems don't support user home directories; for those, fail
return _instance;
}

var settingsDir = getDartStorageDirectory();
if (settingsDir == null) {
// Some systems don't support user home directories; for those, fail
// gracefully by returning a disabled analytics object.
_instance = DisabledAnalytics(_trackingId, _appName);
return _instance;
}

if (!settingsDir.existsSync()) {
try {
settingsDir.createSync();
} catch (e) {
// If we can't create the directory for the analytics settings, fail
// gracefully by returning a disabled analytics object.
_instance = DisabledAnalytics(_trackingId, _appName);
} else if (!settingsDir.existsSync()) {
try {
settingsDir.createSync();
} catch (e) {
// If we can't create the directory for the analytics settings, fail
// gracefully by returning a disabled analytics object.
_instance = DisabledAnalytics(_trackingId, _appName);
}
} else {
var readmeFile =
File('${settingsDir.absolute.path}${path.separator}$_readmeFileName');
if (!readmeFile.existsSync()) {
readmeFile.createSync();
readmeFile.writeAsStringSync(_readmeFileContents);
}

var settingsFile = File(path.join(settingsDir.path, _settingsFileName));
_instance = DartdevAnalytics(_trackingId, settingsFile, _appName);
return _instance;
}
}

var readmeFile =
File('${settingsDir.absolute.path}${path.separator}$_readmeFileName');
if (!readmeFile.existsSync()) {
readmeFile.createSync();
readmeFile.writeAsStringSync(_readmeFileContents);
}

var settingsFile = File(path.join(settingsDir.path, _settingsFileName));
_instance = DartdevAnalytics(_trackingId, settingsFile, _appName);
return _instance;
}

Expand Down

0 comments on commit 5918aa8

Please sign in to comment.