asExec method

Future<bool> asExec(
  1. String filePath, {
  2. bool sudo = false,
})

give filePath executable permissions If sudo is true, the file will be given executable permissions with sudo

Implementation

Future<bool> asExec(String filePath, {bool sudo = false}) async {
  try {
    if (Platform.isWindows) {
      return true;
    } else {
      final result = await simple('chmod', ['+x', filePath], sudo: sudo);
      if (result.exitCode != 0) {
        return false;
      }
    }
  } catch (e) {
    return false;
  }

  final file = File(filePath);

  return file.existsSync() && file.statSync().modeString().contains('x');
}