Skip to content

Commit

Permalink
fix: Change separator based on whether the path is in Windows style
Browse files Browse the repository at this point in the history
  • Loading branch information
blendthink committed Sep 18, 2024
1 parent e0fa434 commit d8412c1
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class UpdateCommandService {

File _getPubspecFile() {
final pubspecFile = File(
'${Directory.current.path}/pubspec.yaml',
[
Directory.current.path,
'pubspec.yaml',
].join(_separator),
);
if (!pubspecFile.existsSync()) {
throw Exception(
Expand Down Expand Up @@ -227,7 +230,10 @@ class UpdateCommandService {

void _updateAnalysisOptionsFile(String includeLine) {
final analysisOptionsFile = File(
'${Directory.current.path}/analysis_options.yaml',
[
Directory.current.path,
'analysis_options.yaml',
].join(_separator),
);
if (!analysisOptionsFile.existsSync()) {
// Create analysis_options.yaml if it does not exist
Expand Down Expand Up @@ -278,3 +284,20 @@ extension _FileSystemEntityName on FileSystemEntity {
return path.split('/').last;
}
}

bool get _isWindowsStyle {
if (Uri.base.scheme != 'file') {
return false;
}
if (!Uri.base.path.endsWith('/')) {
return false;
}
return Uri(path: 'a/b').toFilePath() == r'a\b';
}

String get _separator {
if (_isWindowsStyle) {
return r'\';
}
return '/';
}

0 comments on commit d8412c1

Please sign in to comment.