changeDirectory method

  1. @override
void changeDirectory(
  1. String path
)
override

Changes the current working directory to the specified path.

Implementation

@override
void changeDirectory(String path) {
  final fullPath = resolvePath(path);

  if (Directory(fullPath).existsSync()) {
    final virtualDirName = directoryMappings.keys.firstWhere(
        (key) => fullPath.startsWith(directoryMappings[key]!),
        orElse: () => rootDirectory);

    currentDirectory = p.normalize(p.join(
        rootDirectory,
        virtualDirName,
        p.relative(fullPath,
            from: directoryMappings[virtualDirName] ?? rootDirectory)));
  } else {
    throw FileSystemException("Directory not found or access denied", path);
  }
}