devToolsFileFromPath static method

  1. @Deprecated("Replaced by 'FileSystemExtension.devToolsFileFromPath'")
File? devToolsFileFromPath(
  1. String pathFromDevToolsDir
)

Returns a DevTools file from the given path.

Only files within ~/.flutter-devtools/ can be accessed.

Implementation

@Deprecated("Replaced by 'FileSystemExtension.devToolsFileFromPath'")
static io.File? devToolsFileFromPath(String pathFromDevToolsDir) {
  if (pathFromDevToolsDir.contains('..') ||
      path.isAbsolute(pathFromDevToolsDir)) {
    // The passed in path should not be able to walk up the directory tree
    // outside of the ~/.flutter-devtools/ directory. It must also not be an
    // absolute path: path.join() discards the base directory when its second
    // argument is absolute, which would otherwise allow reading an arbitrary
    // file on disk (e.g. an absolute path to a credentials .json file).
    return null;
  }

  ensureDevToolsDirectory();
  final devToolsDirPath = devToolsDir();
  final file = io.File(path.join(devToolsDirPath, pathFromDevToolsDir));
  // Defense in depth: ensure the resolved path is actually contained within
  // the DevTools directory.
  if (!path.isWithin(devToolsDirPath, file.path)) {
    return null;
  }
  if (!file.existsSync()) {
    return null;
  }
  return file;
}