Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions codex-rs/app-server/src/request_processors/fs_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ impl FsRequestProcessor {
&self,
params: FsCopyParams,
) -> Result<FsCopyResponse, JSONRPCErrorError> {
let source_path = PathUri::from_abs_path(&params.source_path).map_err(map_fs_error)?;
let destination_path =
PathUri::from_abs_path(&params.destination_path).map_err(map_fs_error)?;
self.file_system()?
.copy(
&params.source_path,
&params.destination_path,
&source_path,
&destination_path,
CopyOptions {
recursive: params.recursive,
},
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/config/src/loader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl ExecutorFileSystem for TestFileSystem {

async fn copy(
&self,
_source_path: &AbsolutePathBuf,
_destination_path: &AbsolutePathBuf,
_source_path: &PathUri,
_destination_path: &PathUri,
_copy_options: CopyOptions,
_sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/core/tests/suite/remote_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@ async fn remote_test_env_copy_preserves_symlink_source() -> Result<()> {
let sandbox = workspace_write_sandbox(allowed_dir.clone());
file_system
.copy(
&absolute_path(source_symlink),
&absolute_path(copied_symlink.clone()),
&PathUri::from_path(&source_symlink)?,
&PathUri::from_path(&copied_symlink)?,
CopyOptions { recursive: false },
Some(&sandbox),
)
Expand Down
9 changes: 7 additions & 2 deletions codex-rs/exec-server/src/fs_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,15 @@ pub(crate) async fn run_direct_request(
Ok(FsHelperPayload::Remove(FsRemoveResponse {}))
}
FsHelperRequest::Copy(params) => {
let source_path = codex_utils_path_uri::PathUri::from_abs_path(&params.source_path)
.map_err(map_fs_error)?;
let destination_path =
codex_utils_path_uri::PathUri::from_abs_path(&params.destination_path)
.map_err(map_fs_error)?;
file_system
.copy(
&params.source_path,
&params.destination_path,
&source_path,
&destination_path,
CopyOptions {
recursive: params.recursive,
},
Expand Down
24 changes: 12 additions & 12 deletions codex-rs/exec-server/src/local_file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ impl ExecutorFileSystem for LocalFileSystem {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
Expand Down Expand Up @@ -238,8 +238,8 @@ impl ExecutorFileSystem for UnsandboxedFileSystem {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
Expand Down Expand Up @@ -382,14 +382,14 @@ impl ExecutorFileSystem for DirectFileSystem {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
reject_sandbox_context(sandbox)?;
let source_path = source_path.to_path_buf();
let destination_path = destination_path.to_path_buf();
let source_path = source_path.to_abs_path()?.into_path_buf();
let destination_path = destination_path.to_abs_path()?.into_path_buf();
tokio::task::spawn_blocking(move || -> FileSystemResult<()> {
let metadata = std::fs::symlink_metadata(source_path.as_path())?;
let file_type = metadata.file_type();
Expand Down Expand Up @@ -550,6 +550,10 @@ fn system_time_to_unix_ms(time: SystemTime) -> i64 {
.unwrap_or(0)
}

#[cfg(all(test, any(unix, windows)))]
#[path = "local_file_system_path_uri_tests.rs"]
mod path_uri_tests;

#[cfg(all(test, unix))]
mod tests {
use super::*;
Expand Down Expand Up @@ -605,7 +609,3 @@ mod tests {
Ok(())
}
}

#[cfg(all(test, any(unix, windows)))]
#[path = "local_file_system_path_uri_tests.rs"]
mod path_uri_tests;
20 changes: 11 additions & 9 deletions codex-rs/exec-server/src/remote_file_system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use base64::Engine as _;
use base64::engine::general_purpose::STANDARD;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use tokio::io;
use tracing::trace;
Expand Down Expand Up @@ -195,17 +194,19 @@ impl ExecutorFileSystem for RemoteFileSystem {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
trace!("remote fs copy");
let source_path = source_path.to_abs_path()?;
let destination_path = destination_path.to_abs_path()?;
let client = self.client.get().await.map_err(map_remote_error)?;
client
.fs_copy(FsCopyParams {
source_path: source_path.clone(),
destination_path: destination_path.clone(),
source_path,
destination_path,
recursive: options.recursive,
sandbox: remote_sandbox_context(sandbox),
})
Expand Down Expand Up @@ -239,6 +240,10 @@ fn map_remote_error(error: ExecServerError) -> io::Error {
}
}

#[cfg(all(test, any(unix, windows)))]
#[path = "remote_file_system_path_uri_tests.rs"]
mod path_uri_tests;

#[cfg(test)]
mod tests {
use codex_protocol::models::PermissionProfile;
Expand All @@ -248,6 +253,7 @@ mod tests {
use codex_protocol::permissions::FileSystemSandboxPolicy;
use codex_protocol::permissions::FileSystemSpecialPath;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_utils_absolute_path::AbsolutePathBuf;
use pretty_assertions::assert_eq;

use super::*;
Expand Down Expand Up @@ -328,7 +334,3 @@ mod tests {
AbsolutePathBuf::from_absolute_path(&path).expect("absolute path")
}
}

#[cfg(all(test, any(unix, windows)))]
#[path = "remote_file_system_path_uri_tests.rs"]
mod path_uri_tests;
9 changes: 4 additions & 5 deletions codex-rs/exec-server/src/sandboxed_file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use async_trait::async_trait;
use base64::Engine as _;
use base64::engine::general_purpose::STANDARD;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use tokio::io;

Expand Down Expand Up @@ -218,17 +217,17 @@ impl ExecutorFileSystem for SandboxedFileSystem {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
let sandbox = require_platform_sandbox(sandbox)?;
self.run_sandboxed(
sandbox,
FsHelperRequest::Copy(FsCopyParams {
source_path: source_path.clone(),
destination_path: destination_path.clone(),
source_path: source_path.to_abs_path()?,
destination_path: destination_path.to_abs_path()?,
recursive: options.recursive,
sandbox: None,
}),
Expand Down
7 changes: 5 additions & 2 deletions codex-rs/exec-server/src/server/file_system_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ impl FileSystemHandler {
&self,
params: FsCopyParams,
) -> Result<FsCopyResponse, JSONRPCErrorError> {
let source_path = PathUri::from_abs_path(&params.source_path).map_err(map_fs_error)?;
let destination_path =
PathUri::from_abs_path(&params.destination_path).map_err(map_fs_error)?;
self.file_system
.copy(
&params.source_path,
&params.destination_path,
&source_path,
&destination_path,
CopyOptions {
recursive: params.recursive,
},
Expand Down
16 changes: 8 additions & 8 deletions codex-rs/exec-server/tests/file_system/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ async fn file_system_copy_copies_file(implementation: FileSystemImplementation)

file_system
.copy(
&absolute_path(&source_file),
&absolute_path(&copied_file),
&PathUri::from_path(&source_file)?,
&PathUri::from_path(&copied_file)?,
CopyOptions { recursive: false },
/*sandbox*/ None,
)
Expand Down Expand Up @@ -243,8 +243,8 @@ async fn file_system_copy_copies_directory_recursively(

file_system
.copy(
&absolute_path(&source_dir),
&absolute_path(&copied_dir),
&PathUri::from_path(&source_dir)?,
&PathUri::from_path(&copied_dir)?,
CopyOptions { recursive: true },
/*sandbox*/ None,
)
Expand Down Expand Up @@ -373,8 +373,8 @@ async fn file_system_copy_rejects_directory_without_recursive(

let error = file_system
.copy(
&absolute_path(&source_dir),
&absolute_path(tmp.path().join("dest")),
&PathUri::from_path(&source_dir)?,
&PathUri::from_path(tmp.path().join("dest"))?,
CopyOptions { recursive: false },
/*sandbox*/ None,
)
Expand Down Expand Up @@ -543,8 +543,8 @@ async fn file_system_copy_rejects_copying_directory_into_descendant(

let error = file_system
.copy(
&absolute_path(&source_dir),
&absolute_path(source_dir.join("nested").join("copy")),
&PathUri::from_path(&source_dir)?,
&PathUri::from_path(source_dir.join("nested").join("copy"))?,
CopyOptions { recursive: true },
/*sandbox*/ None,
)
Expand Down
4 changes: 1 addition & 3 deletions codex-rs/exec-server/tests/file_system/support.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt;
use std::path::Path;
use std::sync::Arc;

use anyhow::Result;
Expand Down Expand Up @@ -71,8 +70,7 @@ pub(crate) async fn create_file_system_context(
}
}

pub(crate) fn absolute_path(path: impl AsRef<Path>) -> AbsolutePathBuf {
let path = path.as_ref().to_path_buf();
pub(crate) fn absolute_path(path: std::path::PathBuf) -> AbsolutePathBuf {
assert!(
path.is_absolute(),
"path must be absolute: {}",
Expand Down
25 changes: 12 additions & 13 deletions codex-rs/exec-server/tests/file_system_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use test_case::test_case;
use crate::common::exec_server::exec_server_with_env;

use crate::support::FileSystemImplementation;
use crate::support::absolute_path;
use crate::support::create_file_system_context;
use crate::support::read_only_sandbox;
use crate::support::workspace_write_sandbox;
Expand Down Expand Up @@ -545,8 +544,8 @@ async fn file_system_copy_rejects_symlink_escape_destination(
let sandbox = workspace_write_sandbox(allowed_dir.clone());
let error = match file_system
.copy(
&absolute_path(allowed_dir.join("source.txt")),
&absolute_path(&requested_destination),
&PathUri::from_path(allowed_dir.join("source.txt"))?,
&PathUri::from_path(&requested_destination)?,
CopyOptions { recursive: false },
Some(&sandbox),
)
Expand Down Expand Up @@ -623,8 +622,8 @@ async fn file_system_copy_preserves_symlink_source(
let sandbox = workspace_write_sandbox(allowed_dir.clone());
file_system
.copy(
&absolute_path(&source_symlink),
&absolute_path(&copied_symlink),
&PathUri::from_path(&source_symlink)?,
&PathUri::from_path(&copied_symlink)?,
CopyOptions { recursive: false },
Some(&sandbox),
)
Expand Down Expand Up @@ -701,8 +700,8 @@ async fn file_system_copy_rejects_symlink_escape_source(
let sandbox = workspace_write_sandbox(allowed_dir);
let error = match file_system
.copy(
&absolute_path(&requested_source),
&absolute_path(&requested_destination),
&PathUri::from_path(&requested_source)?,
&PathUri::from_path(&requested_destination)?,
CopyOptions { recursive: false },
Some(&sandbox),
)
Expand Down Expand Up @@ -735,8 +734,8 @@ async fn file_system_copy_preserves_symlinks_in_recursive_copy(

file_system
.copy(
&absolute_path(&source_dir),
&absolute_path(&copied_dir),
&PathUri::from_path(&source_dir)?,
&PathUri::from_path(&copied_dir)?,
CopyOptions { recursive: true },
/*sandbox*/ None,
)
Expand Down Expand Up @@ -781,8 +780,8 @@ async fn file_system_copy_ignores_unknown_special_files_in_recursive_copy(

file_system
.copy(
&absolute_path(&source_dir),
&absolute_path(&copied_dir),
&PathUri::from_path(&source_dir)?,
&PathUri::from_path(&copied_dir)?,
CopyOptions { recursive: true },
/*sandbox*/ None,
)
Expand Down Expand Up @@ -820,8 +819,8 @@ async fn file_system_copy_rejects_standalone_fifo_source(

let error = file_system
.copy(
&absolute_path(&fifo_path),
&absolute_path(tmp.path().join("copied")),
&PathUri::from_path(&fifo_path)?,
&PathUri::from_path(tmp.path().join("copied"))?,
CopyOptions { recursive: false },
/*sandbox*/ None,
)
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/ext/skills/tests/executor_file_system_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ impl ExecutorFileSystem for SyntheticFileSystem {

async fn copy(
&self,
_source_path: &AbsolutePathBuf,
_destination_path: &AbsolutePathBuf,
_source_path: &PathUri,
_destination_path: &PathUri,
_options: CopyOptions,
_sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()> {
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/file-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ pub trait ExecutorFileSystem: Send + Sync {

async fn copy(
&self,
source_path: &AbsolutePathBuf,
destination_path: &AbsolutePathBuf,
source_path: &PathUri,
destination_path: &PathUri,
copy_options: CopyOptions,
sandbox: Option<&FileSystemSandboxContext>,
) -> FileSystemResult<()>;
Expand Down
Loading