| OLD | NEW |
| (Empty) |
| 1 | |
| 2 library which.src.is_executable; | |
| 3 | |
| 4 import 'dart:async'; | |
| 5 import 'dart:io'; | |
| 6 | |
| 7 import 'package:when/when.dart'; | |
| 8 | |
| 9 import 'has_permission.dart'; | |
| 10 | |
| 11 Future<bool> isExecutable(String path, bool isWindows, Future<FileStat> getStat(
path)) => | |
| 12 _isExecutable(path, isWindows, getStat); | |
| 13 | |
| 14 bool isExecutableSync(String path, bool isWindows, FileStat getStat(path)) => | |
| 15 _isExecutable(path, isWindows, getStat); | |
| 16 | |
| 17 _isExecutable(String path, bool isWindows, getStat(path)) => | |
| 18 when(() => getStat(path), onSuccess: (stat) => isExecutableStat(stat, isWind
ows)); | |
| 19 | |
| 20 /// Tests whether the file exists and is executable. | |
| 21 bool isExecutableStat(FileStat stat, bool isWindows) { | |
| 22 if (FileSystemEntityType.FILE != stat.type) return false; | |
| 23 | |
| 24 // There is no concept of executable on windows. | |
| 25 if (isWindows) return true; | |
| 26 | |
| 27 // TODO: This currently produces false positives (returns true when it | |
| 28 // shouldn't) when the uid/gid of current user and executable don't | |
| 29 // match. Fix if/when uid/gid support is added: | |
| 30 // http://dartbug.com/22037. | |
| 31 return FilePermissionRole.values.any((role) => | |
| 32 hasPermission(stat.mode, FilePermission.EXECUTE, role: role)); | |
| 33 } | |
| OLD | NEW |