Browse Source

Removed the `Finder.pathSeparator` property

tags/v8.0.0
Cédric Belin 2 weeks ago
parent
commit
d59698bebf
4 changed files with 6 additions and 29 deletions
  1. +0
    -8
      doc/usage/api.md
  2. +0
    -4
      lib/src/io/file_stat.dart
  3. +4
    -12
      lib/src/io/finder.dart
  4. +2
    -5
      lib/src/io/where.dart

+ 0
- 8
doc/usage/api.md View File

@@ -76,11 +76,3 @@ The system path, provided as a string or a list of directories. Defaults to the
where("foobar", path: "/usr/local/bin:/usr/bin");
where("foobar", path: ["/usr/local/bin", "/usr/bin"]);
```

### String **pathSeparator**
The character used to separate paths in the system path. Defaults to the platform path separator (i.e. `";"` on Windows, `":"` on other platforms).

``` dart
where("foobar", pathSeparator: "#");
// For example: "/usr/local/bin#/usr/bin"
```

+ 0
- 4
lib/src/io/file_stat.dart View File

@@ -18,8 +18,6 @@ class FileStat implements io.FileStat {
/// Completes with a [FileStat] object containing the data returned by `stat()`.
/// If the call fails, completes the future with a [FileStat] object with [type] set to `FileSystemEntityType.notFound` and the other fields invalid.
static Future<FileStat> stat(String path) async {
assert(path.isNotEmpty);

final stats = await io.FileStat.stat(path);
if (Finder.isWindows) return FileStat._fromStats(stats);

@@ -40,8 +38,6 @@ class FileStat implements io.FileStat {
/// Returns a [FileStat] object containing the data returned by `stat()`.
/// If the call fails, returns a [FileStat] object with [type] set to `FileSystemEntityType.notFound` and the other fields invalid.
static FileStat statSync(String path) { // ignore: prefer_constructors_over_static_methods
assert(path.isNotEmpty);

final stats = io.FileStat.statSync(path);
if (Finder.isWindows) return FileStat._fromStats(stats);



+ 4
- 12
lib/src/io/finder.dart View File

@@ -6,9 +6,8 @@ class Finder {
/// Creates a new finder from the following parameters:
/// - [extensions]: A string, or a list of strings, specifying the executable file extensions. Defaults to the `PATHEXT` environment variable.
/// - [path]: A string, or a list of strings, specifying the system path. Defaults to the `PATH` environment variable.
/// - [pathSeparator]: The character used to separate paths in the system path. Defaults to the platform path separator.
Finder({List<String> extensions, List<String> path, String pathSeparator}) {
this.pathSeparator = pathSeparator ?? (isWindows ? ";" : ":");
Finder({List<String> extensions, List<String> path}) {
final pathSeparator = isWindows ? ";" : ":";

if (path is! List) path = path.toString().split(pathSeparator)..retainWhere((item) => item.isNotEmpty);
if (path.isEmpty) {
@@ -38,9 +37,6 @@ class Finder {
/// The list of system paths.
final List<String> path = <String>[];

/// The character used to separate paths in the system path.
String pathSeparator;

/// Finds the instances of the specified [command] in the system path.
Stream<io.File> find(String command) async* {
for (final directory in path) yield* _findExecutables(directory, command);
@@ -48,7 +44,6 @@ class Finder {

/// Gets a value indicating whether the specified [file] is executable.
Future<bool> isExecutable(String file) async {
assert(file.isNotEmpty);
final type = io.FileSystemEntity.typeSync(file);
if (type != io.FileSystemEntityType.file && type != io.FileSystemEntityType.link) return false;
return isWindows ? _checkFileExtension(file) : _checkFilePermissions(await FileStat.stat(file));
@@ -79,9 +74,6 @@ class Finder {

/// Finds the instances of a [command] in the specified [directory].
Stream<io.File> _findExecutables(String directory, String command) async* {
assert(directory.isNotEmpty);
assert(command.isNotEmpty);

for (final extension in ["", ...extensions]) {
final resolvedPath = p.canonicalize("${p.join(directory, command)}${extension.toLowerCase()}");
if (await isExecutable(resolvedPath)) yield io.File(resolvedPath);
@@ -90,7 +82,6 @@ class Finder {

/// Gets a numeric [identity] of the process.
Future<int> _getProcessId(String identity) async {
assert(identity.isNotEmpty);
if (isWindows) return -1;
final result = await io.Process.run("id", ["-$identity"]);
return result.exitCode != 0 ? -1 : int.tryParse(result.stdout.trim(), radix: 10) ?? -1;
@@ -101,7 +92,8 @@ class Finder {
class FinderException implements io.IOException {

/// Creates a new finder exception.
FinderException(this.command, this.finder, [this.message = ""]): assert(command.isNotEmpty);
FinderException(this.command, this.finder, [String message]):
message = message ?? "Command '$command' not found.";

/// The looked up command.
final String command;


+ 2
- 5
lib/src/io/where.dart View File

@@ -9,11 +9,8 @@ part of "../io.dart";
/// Optional parameters allow to customize the function behavior:
/// - [path]: A string, or a list of strings, specifying the system path. Defaults to the `PATH` environment variable.
/// - [extensions]: A string, or a list of strings, specifying the executable file extensions. Defaults to the `PATHEXT` environment variable.
/// - [pathSeparator]: The character used to separate paths in the system path. Defaults to the platform path separator.
Future where(String command, {bool all = false, extensions = "", Function(String command) onError, path = "", String pathSeparator = ""}) async {
assert(command.isNotEmpty);

final finder = Finder(extensions: extensions, path: path, pathSeparator: pathSeparator);
Future where(String command, {bool all = false, extensions = "", Function(String command) onError, path = ""}) async {
final finder = Finder(extensions: extensions, path: path);
final list = <String>[];

await for (final executable in finder.find(command)) {


Loading…
Cancel
Save