rm method

Future<void> rm(
  1. String pathSpec, {
  2. bool rmFromFs = true,
})

Implementation

Future<void> rm(String pathSpec, {bool rmFromFs = true}) async {
  pathSpec = normalizePath(pathSpec);

  var index = await indexStorage.readIndex();

  var stat = await fs.stat(pathSpec);
  if (stat.type == FileSystemEntityType.file) {
    await rmFileFromIndex(index, pathSpec);
    if (rmFromFs) {
      await fs.file(pathSpec).delete();
    }
  } else if (stat.type == FileSystemEntityType.directory) {
    await rmDirectoryFromIndex(index, pathSpec, recursive: true);
    if (rmFromFs) {
      await fs.directory(pathSpec).delete(recursive: true);
    }
  } else {
    throw Exception('Neither file or directory');
  }

  await indexStorage.writeIndex(index);
}