mirror of
https://github.com/openai/codex.git
synced 2026-11-20 15:07:25 +00:00
Avoid redundant filesystem metadata probes (#36898)
## What changed - Reuse directory-entry file types in local memory listing while continuing to exclude symlinks, and reuse rollout metadata when reading modification times. - Avoid following non-symlinks twice in direct filesystem metadata and directory listing operations while preserving target classification for valid symlinks. ## Testing - Cover symlink handling in local memory listing and search. - Extend Unix filesystem tests for followed file and directory symlinks and dangling metadata links. GitOrigin-RevId: e4e24576e2e9db704f9da54727928e121f81dc86
This commit is contained in:
1 parent
17df7545a3
commit
40e5de94e9
7 files changed
+171
-35
No files matched your search
@@ -32,12 +32,10 @@ pub fn spawn_rollout_compression_worker(codex_home: PathBuf) {
|
||||
|
||||
/// Returns the modified time for the existing plain or compressed rollout file.
|
||||
pub(crate) async fn file_modified_time(path: &Path) -> io::Result<Option<time::OffsetDateTime>> {
|
||||
let Some(path) = path::existing_rollout_path(path).await else {
|
||||
return Ok(None);
|
||||
};
|
||||
let meta = tokio::fs::metadata(path).await?;
|
||||
let modified = meta.modified().ok();
|
||||
Ok(modified.map(time::OffsetDateTime::from))
|
||||
Ok(path::existing_rollout_with_metadata(path)
|
||||
.await
|
||||
.and_then(|(_, metadata)| metadata.modified().ok())
|
||||
.map(time::OffsetDateTime::from))
|
||||
}
|
||||
|
||||
/// Opens a rollout line reader that transparently handles plain `.jsonl` and `.jsonl.zst` files.
|
||||
@@ -936,6 +934,7 @@ pub async fn existing_rollout_path(path: &Path) -> Option<PathBuf> {
|
||||
|
||||
mod path {
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::Metadata;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -974,15 +973,26 @@ mod path {
|
||||
}
|
||||
|
||||
pub(super) async fn existing_rollout_path(path: &Path) -> Option<PathBuf> {
|
||||
existing_rollout_with_metadata(path)
|
||||
.await
|
||||
.map(|(path, _)| path)
|
||||
}
|
||||
|
||||
/// Resolves the plain rollout before its compressed sibling and retains the lookup metadata.
|
||||
///
|
||||
/// Returning the metadata lets callers inspect the selected file without a second stat.
|
||||
pub(super) async fn existing_rollout_with_metadata(path: &Path) -> Option<(PathBuf, Metadata)> {
|
||||
let plain_path = plain_rollout_path(path);
|
||||
if matches!(tokio::fs::metadata(plain_path.as_path()).await, Ok(metadata) if metadata.is_file())
|
||||
if let Ok(metadata) = tokio::fs::metadata(plain_path.as_path()).await
|
||||
&& metadata.is_file()
|
||||
{
|
||||
return Some(plain_path);
|
||||
return Some((plain_path, metadata));
|
||||
}
|
||||
let compressed_path = compressed_rollout_path(plain_path.as_path());
|
||||
if matches!(tokio::fs::metadata(compressed_path.as_path()).await, Ok(metadata) if metadata.is_file())
|
||||
if let Ok(metadata) = tokio::fs::metadata(compressed_path.as_path()).await
|
||||
&& metadata.is_file()
|
||||
{
|
||||
return Some(compressed_path);
|
||||
return Some((compressed_path, metadata));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user