Migrate ExecutorFileSystem read_directory to PathUri

This commit is contained in:
Codex
2026-06-10 22:15:28 +00:00
committed by Adam Perry
parent c0dda81226
commit b76475bc76
13 changed files with 38 additions and 20 deletions
+3 -1
View File
@@ -258,8 +258,10 @@ pub(crate) async fn run_direct_request(
}))
}
FsHelperRequest::ReadDirectory(params) => {
let path =
codex_utils_path_uri::PathUri::from_abs_path(&params.path).map_err(map_fs_error)?;
let entries = file_system
.read_directory(&params.path, /*sandbox*/ None)
.read_directory(&path, /*sandbox*/ None)
.await
.map_err(map_fs_error)?
.into_iter()
@@ -129,7 +129,7 @@ impl ExecutorFileSystem for LocalFileSystem {
async fn read_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<Vec<ReadDirectoryEntry>> {
let (file_system, sandbox) = self.file_system_for(sandbox)?;
@@ -215,7 +215,7 @@ impl ExecutorFileSystem for UnsandboxedFileSystem {
async fn read_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<Vec<ReadDirectoryEntry>> {
reject_platform_sandbox_context(sandbox)?;
@@ -333,10 +333,11 @@ impl ExecutorFileSystem for DirectFileSystem {
async fn read_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<Vec<ReadDirectoryEntry>> {
reject_sandbox_context(sandbox)?;
let path = path.to_abs_path()?;
let mut entries = Vec::new();
let mut read_dir = tokio::fs::read_dir(path.as_path()).await?;
while let Some(entry) = read_dir.next_entry().await? {
@@ -148,14 +148,15 @@ impl ExecutorFileSystem for RemoteFileSystem {
async fn read_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<Vec<ReadDirectoryEntry>> {
trace!("remote fs read_directory");
let path = path.to_abs_path()?;
let client = self.client.get().await.map_err(map_remote_error)?;
let response = client
.fs_read_directory(FsReadDirectoryParams {
path: path.clone(),
path,
sandbox: remote_sandbox_context(sandbox),
})
.await
@@ -168,7 +168,7 @@ impl ExecutorFileSystem for SandboxedFileSystem {
async fn read_directory(
&self,
path: &AbsolutePathBuf,
path: &PathUri,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<Vec<ReadDirectoryEntry>> {
let sandbox = require_platform_sandbox(sandbox)?;
@@ -176,7 +176,7 @@ impl ExecutorFileSystem for SandboxedFileSystem {
.run_sandboxed(
sandbox,
FsHelperRequest::ReadDirectory(FsReadDirectoryParams {
path: path.clone(),
path: path.to_abs_path()?,
sandbox: None,
}),
)
@@ -153,9 +153,10 @@ impl FileSystemHandler {
&self,
params: FsReadDirectoryParams,
) -> Result<FsReadDirectoryResponse, JSONRPCErrorError> {
let path = PathUri::from_abs_path(&params.path).map_err(map_fs_error)?;
let entries = self
.file_system
.read_directory(&params.path, params.sandbox.as_ref())
.read_directory(&path, params.sandbox.as_ref())
.await
.map_err(map_fs_error)?
.into_iter()
@@ -273,7 +273,7 @@ async fn file_system_read_directory_lists_entries(
std::fs::write(source_dir.join("root.txt"), "hello")?;
let mut entries = file_system
.read_directory(&absolute_path(&source_dir), /*sandbox*/ None)
.read_directory(&PathUri::from_path(&source_dir)?, /*sandbox*/ None)
.await
.with_context(|| format!("mode={implementation}"))?;
entries.sort_by(|left, right| left.file_name.cmp(&right.file_name));
@@ -513,7 +513,7 @@ async fn file_system_read_directory_rejects_symlink_escape(
let requested_path = allowed_dir.join("link");
let sandbox = read_only_sandbox(allowed_dir);
let error = match file_system
.read_directory(&absolute_path(&requested_path), Some(&sandbox))
.read_directory(&PathUri::from_path(&requested_path)?, Some(&sandbox))
.await
{
Ok(_) => anyhow::bail!("read_directory should be blocked"),