Skip to content

Commit

Permalink
Add universal path context
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 23, 2024
1 parent 2e1d530 commit 423982e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/lw_file_system_api/lib/src/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:path/path.dart' as p;

part 'location.mapper.dart';

final universalPathContext = p.Context(style: p.Style.posix, current: '/');

@MappableClass()
class AssetLocation with AssetLocationMappable {
final String remote;
Expand Down Expand Up @@ -41,7 +43,8 @@ class AssetLocation with AssetLocationMappable {

String get fileName => p.basename(path);

String get fileNameWithoutExtension => p.basenameWithoutExtension(path);
String get fileNameWithoutExtension =>
universalPathContext.basenameWithoutExtension(path);

String get parent => p.dirname(path);

Expand All @@ -50,10 +53,12 @@ class AssetLocation with AssetLocationMappable {
}

AssetLocation buildChildLocation(String child) {
return AssetLocation(path: p.join(path, child), remote: remote);
return AssetLocation(
path: universalPathContext.join(path, child), remote: remote);
}

AssetLocation buildSiblingLocation(String sibling) {
return AssetLocation(path: p.join(parent, sibling), remote: remote);
return AssetLocation(
path: universalPathContext.join(parent, sibling), remote: remote);
}
}
4 changes: 2 additions & 2 deletions packages/lw_file_system_api/lib/src/name.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:path/path.dart' as p;
import 'package:lw_file_system_api/lw_file_system_api.dart';

const invalidFileName = r'[\\/:\*\?"<>\|\n\0-\x1F\x7F-\xFF]';

Expand All @@ -15,7 +15,7 @@ String convertNameToFile({
name = getUnnamed();
}
name = name.replaceAll(invalidFileName, '_');
return p.join(directory, '$name$suffix');
return universalPathContext.join(directory, '$name$suffix');
}

bool hasInvalidFileName(String name) => RegExp(invalidFileName).hasMatch(name);
Expand Down

0 comments on commit 423982e

Please sign in to comment.