init method

void init()

Initialize the cache directories.

This method does not normally need to be called explicitly as the constructor will call it.

Implementation

void init() {
  final root = Directory(rootDir);
  final versionFile = File(path.join(rootDir, 'version'));
  bool requiresUpdate;
  if (root.existsSync()) {
    requiresUpdate = !_isCurrentVersion(versionFile);
    if (requiresUpdate) {
      logger.info(
          'Dartle cache version change detected. Performing full cleanup.');
      ignoreExceptions(
          () => Directory(_hashesDir).deleteSync(recursive: true));
      ignoreExceptions(
          () => Directory(_tasksDir).deleteSync(recursive: true));
      ignoreExceptions(
          () => Directory(_executablesDir).deleteSync(recursive: true));
    }
  } else {
    root.createSync(recursive: true);
    requiresUpdate = true;
  }
  if (requiresUpdate) {
    versionFile.writeAsStringSync(cacheFormatVersion);
  }
  Directory(_hashesDir).createSync();
  Directory(_tasksDir).createSync();
  Directory(_executablesDir).createSync();
  logger.fine(() =>
      'Cache initialized at ${path.join(Directory.current.path, rootDir)}');
}