prepareRoot method

Future<bool> prepareRoot(
  1. List<String> rootPath
)

Prepare a root node with given path

Implementation

Future<bool> prepareRoot(List<String> rootPath) async {
  bool checkNode = await isNodeExist(':${rootPath.join(':')}');
  if (checkNode) {
    log('Root path has already existed $rootPath');
    return true;
  }
  String currentRoot = '';
  int currentIndex = 0;
  while (currentIndex < rootPath.length) {
    try {
      await storageController!.addOrUpdate(
        NodeImpl(rootPath[currentIndex], pluginId,
            currentRoot == '' ? ':' : currentRoot, Visibility.white),
      );
      currentRoot = '$currentRoot:${rootPath[currentIndex]}';
      currentIndex++;
    } catch (e, trace) {
      log('Failed to prepare the path: $currentRoot:${rootPath[currentIndex]}');
      log(e.toString());
      if (exceptionHandler != null) {
        exceptionHandler!(e, trace);
      }
      return false;
    }
  }
  Node testNode = await storageController!.get(currentRoot);
  log('Root: ${testNode.toString()}');
  return true;
}