isDirWritable function

bool isDirWritable(
  1. Directory dir
)

Whether dir is writable by creating and deleting a probe file.

Implementation

bool isDirWritable(Directory dir) {
  if (!dir.existsSync()) {
    return false;
  }
  try {
    final File probe = File(
      '${dir.path}${Platform.pathSeparator}.adk_probe_${DateTime.now().microsecondsSinceEpoch}',
    );
    probe.writeAsStringSync('probe');
    probe.deleteSync();
    return true;
  } on FileSystemException {
    return false;
  }
}