mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Reuse directory entry metadata for skill scans
This commit is contained in:
@@ -257,6 +257,7 @@ pub(crate) async fn run_direct_request(
|
||||
file_name: entry.file_name,
|
||||
is_directory: entry.is_directory,
|
||||
is_file: entry.is_file,
|
||||
is_symlink: entry.is_symlink,
|
||||
})
|
||||
.collect();
|
||||
Ok(FsHelperPayload::ReadDirectory(FsReadDirectoryResponse {
|
||||
|
||||
@@ -597,13 +597,23 @@ impl DirectFileSystem {
|
||||
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? {
|
||||
let Ok(metadata) = tokio::fs::metadata(entry.path()).await else {
|
||||
let Ok(file_type) = entry.file_type().await else {
|
||||
continue;
|
||||
};
|
||||
let is_symlink = file_type.is_symlink();
|
||||
let (is_directory, is_file) = if is_symlink {
|
||||
let Ok(metadata) = tokio::fs::metadata(entry.path()).await else {
|
||||
continue;
|
||||
};
|
||||
(metadata.is_dir(), metadata.is_file())
|
||||
} else {
|
||||
(file_type.is_dir(), file_type.is_file())
|
||||
};
|
||||
entries.push(ReadDirectoryEntry {
|
||||
file_name: entry.file_name().to_string_lossy().into_owned(),
|
||||
is_directory: metadata.is_dir(),
|
||||
is_file: metadata.is_file(),
|
||||
is_directory,
|
||||
is_file,
|
||||
is_symlink,
|
||||
});
|
||||
}
|
||||
Ok(entries)
|
||||
|
||||
@@ -320,6 +320,8 @@ pub struct FsReadDirectoryEntry {
|
||||
pub file_name: String,
|
||||
pub is_directory: bool,
|
||||
pub is_file: bool,
|
||||
#[serde(default)]
|
||||
pub is_symlink: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@@ -179,6 +179,7 @@ impl RemoteFileSystem {
|
||||
file_name: entry.file_name,
|
||||
is_directory: entry.is_directory,
|
||||
is_file: entry.is_file,
|
||||
is_symlink: entry.is_symlink,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ impl SandboxedFileSystem {
|
||||
file_name: entry.file_name,
|
||||
is_directory: entry.is_directory,
|
||||
is_file: entry.is_file,
|
||||
is_symlink: entry.is_symlink,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -193,6 +193,7 @@ impl FileSystemHandler {
|
||||
file_name: entry.file_name,
|
||||
is_directory: entry.is_directory,
|
||||
is_file: entry.is_file,
|
||||
is_symlink: entry.is_symlink,
|
||||
})
|
||||
.collect();
|
||||
Ok(FsReadDirectoryResponse { entries })
|
||||
|
||||
@@ -343,11 +343,13 @@ async fn file_system_read_directory_lists_entries(
|
||||
file_name: "nested".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: false,
|
||||
},
|
||||
ReadDirectoryEntry {
|
||||
file_name: "root.txt".to_string(),
|
||||
is_directory: false,
|
||||
is_file: true,
|
||||
is_symlink: false,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
@@ -23,6 +23,7 @@ use codex_exec_server::CreateDirectoryOptions;
|
||||
#[cfg(target_os = "linux")]
|
||||
use codex_exec_server::Environment;
|
||||
use codex_exec_server::FileMetadata;
|
||||
use codex_exec_server::ReadDirectoryEntry;
|
||||
use codex_exec_server::RemoveOptions;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -79,6 +80,51 @@ fn assert_normalized_path_rejected(error: &std::io::Error) {
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case(FileSystemImplementation::Local ; "local")]
|
||||
#[test_case(FileSystemImplementation::Remote ; "remote")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn file_system_read_directory_reports_symlink_target_kind(
|
||||
implementation: FileSystemImplementation,
|
||||
) -> Result<()> {
|
||||
let context = create_file_system_context(implementation).await?;
|
||||
let file_system = context.file_system;
|
||||
|
||||
let tmp = TempDir::new()?;
|
||||
let source_dir = tmp.path().join("source");
|
||||
let target_dir = tmp.path().join("target-dir");
|
||||
let target_file = tmp.path().join("target.txt");
|
||||
std::fs::create_dir_all(&source_dir)?;
|
||||
std::fs::create_dir_all(&target_dir)?;
|
||||
std::fs::write(&target_file, "hello")?;
|
||||
symlink(&target_dir, source_dir.join("directory-link"))?;
|
||||
symlink(&target_file, source_dir.join("file-link"))?;
|
||||
|
||||
let mut entries = file_system
|
||||
.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));
|
||||
assert_eq!(
|
||||
entries,
|
||||
vec![
|
||||
ReadDirectoryEntry {
|
||||
file_name: "directory-link".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: true,
|
||||
},
|
||||
ReadDirectoryEntry {
|
||||
file_name: "file-link".to_string(),
|
||||
is_directory: false,
|
||||
is_file: true,
|
||||
is_symlink: true,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn alias_root_candidate() -> Result<Option<PathBuf>> {
|
||||
for root in [Path::new("/tmp").to_path_buf(), std::env::temp_dir()] {
|
||||
if root.is_dir() && root.canonicalize().is_ok_and(|canonical| canonical != root) {
|
||||
|
||||
Reference in New Issue
Block a user