Skip to content

Adhere to XDG base directory spec #53312

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/analysis_server/benchmark/benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ String get analysisServerSrcPath {
}

void deleteServerCache() {
// ~/.dartServer/.analysis-driver/
// ~/.config/dartServer/.analysis-driver/
var resourceProvider = PhysicalResourceProvider.INSTANCE;
var stateLocation = resourceProvider.getStateLocation('.analysis-driver');
try {
Expand Down
20 changes: 14 additions & 6 deletions pkg/analyzer/lib/file_system/physical_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import 'package:watcher/watcher.dart';

/// The name of the directory containing plugin specific subfolders used to
/// store data across sessions.
const String _serverDir = ".dartServer";
string _serverdir;

/// Returns the path to default state location.
///
/// Generally this is ~/.dartServer. It can be overridden via the
/// Generally this is ~/.config/dartServer. It can be overridden via the
/// ANALYZER_STATE_LOCATION_OVERRIDE environment variable, in which case this
/// method will return the contents of that environment variable.
String? _getStandardStateLocation() {
Expand All @@ -27,10 +27,18 @@ String? _getStandardStateLocation() {
return env['ANALYZER_STATE_LOCATION_OVERRIDE'];
}

final home = io.Platform.isWindows ? env['LOCALAPPDATA'] : env['HOME'];
return home != null && io.FileSystemEntity.isDirectorySync(home)
? join(home, _serverDir)
: null;
if (Platform.isLinux) {
var xdgConfigHome = Platform.environment['XDG_CONFIG_HOME'];
if (xdgConfigHome != null) {
return '$xdgConfigHome/dartServer';
} else {
return '${Platform.environment['HOME']}/.config/dartServer';
}
} else if (Platform.isMacOS) {
return '${Platform.environment['HOME']}/Library/Application Support/dartServer';
} else if (Platform.isWindows) {
return '${Platform.environment['APPDATA']}/dartServer';
}
}

/// A `dart:io` based implementation of [ResourceProvider].
Expand Down
22 changes: 18 additions & 4 deletions pkg/dartdev/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ const String analyticsDisabledNoticeMessage = '''
╚════════════════════════════════════════════════════════════════════════════╝
''';
const String _appName = 'dartdev';
const String _dartDirectoryName = '.dart';
const String _settingsFileName = 'dartdev.json';
const String _trackingId = 'UA-26406144-37';
const String _readmeFileName = 'README.txt';
const String _readmeFileContents = '''
This directory contains user-level settings for the Dart programming language
(https://dart.dev).
''';

String _dartDirectoryName;
const String eventCategory = 'dartdev';
const String exitCodeParam = 'exitCode';

Expand Down Expand Up @@ -102,7 +101,7 @@ Directory? get homeDir {

/// The directory used to store the analytics settings file.
///
/// Typically, the directory is `~/.dart/` (and the settings file is
/// Typically, the directory is `~/.config/dart/` (and the settings file is
/// `dartdev.json`).
///
/// This can return null under some conditions, including when the user's home
Expand All @@ -112,7 +111,22 @@ Directory? getDartStorageDirectory() {
if (dir == null) {
return null;
} else {
return Directory(path.join(dir.path, _dartDirectoryName));
if (Platform.environment.containsKey('DART_CONFIG_DIR')) {
return Platform.environment['DART_CONFIG_DIR'];
} else {
if (Platform.isLinux) {
var xdgConfigHome = Platform.environment['XDG_CONFIG_HOME'];
if (xdgConfigHome != null) {
return '$xdgConfigHome/dart';
} else {
return '${Platform.environment['HOME']}/.config/dart';
}
} else if (Platform.isMacOS) {
return '${Platform.environment['HOME']}/Library/Application Support/dart';
} else if (Platform.isWindows) {
return '${Platform.environment['APPDATA']}/dart';
}
}
}
}

Expand Down