mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
path-uri: narrow host helper PR scope
This commit is contained in:
@@ -30,7 +30,7 @@ use ts_rs::TS;
|
||||
/// `String` and is instead encouraged to convert through [`PathUri`] or
|
||||
/// [`AbsolutePathBuf`]. Relative path text remains valid until an operation
|
||||
/// such as [`Self::to_path_uri`] requires an absolute path.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, TS)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, TS)]
|
||||
#[serde(transparent)]
|
||||
#[ts(type = "string")]
|
||||
pub struct LegacyAppPathString(String);
|
||||
@@ -81,14 +81,6 @@ impl LegacyAppPathString {
|
||||
})
|
||||
}
|
||||
|
||||
/// Parses this API string as an absolute path native to the current host.
|
||||
///
|
||||
/// Host-specific path namespaces are normalized before the path is converted
|
||||
/// to a URI. Relative and foreign-platform paths are rejected.
|
||||
pub fn to_host_path_uri(&self) -> Result<PathUri, LegacyAppPathStringError> {
|
||||
self.to_path_uri(PathConvention::native())
|
||||
}
|
||||
|
||||
/// Parses this API string as an absolute path native to the current host.
|
||||
///
|
||||
/// Host-specific path namespaces are normalized. Relative and
|
||||
|
||||
@@ -263,50 +263,23 @@ impl PathUri {
|
||||
if self.0.host_str() != base.0.host_str() {
|
||||
return false;
|
||||
}
|
||||
let Some(convention) = self.infer_path_convention() else {
|
||||
let Some(path_segments) = containment_path_segments(
|
||||
&self.0,
|
||||
self.infer_path_convention()
|
||||
.unwrap_or(PathConvention::Posix),
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
if base.infer_path_convention() != Some(convention) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(path_segments) = containment_path_segments(&self.0, convention) else {
|
||||
return false;
|
||||
};
|
||||
let Some(base_segments) = containment_path_segments(&base.0, convention) else {
|
||||
let Some(base_segments) = containment_path_segments(
|
||||
&base.0,
|
||||
base.infer_path_convention()
|
||||
.unwrap_or(PathConvention::Posix),
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
path_segments.starts_with(&base_segments)
|
||||
}
|
||||
|
||||
/// Returns this path relative to `base` using `/` as the separator.
|
||||
///
|
||||
/// Both paths are compared lexically in URI space, without consulting the
|
||||
/// host filesystem. `None` is returned when the paths use different native
|
||||
/// conventions or authorities, when this path is outside `base`, or when an
|
||||
/// encoded native separator makes containment ambiguous.
|
||||
pub fn relative_path_from(&self, base: &Self) -> Option<String> {
|
||||
if self == base {
|
||||
return Some(String::new());
|
||||
}
|
||||
|
||||
let convention = self.infer_path_convention()?;
|
||||
if base.infer_path_convention()? != convention || self.0.host_str() != base.0.host_str() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let path_segments = containment_path_segments(&self.0, convention)?;
|
||||
let base_segments = containment_path_segments(&base.0, convention)?;
|
||||
let relative_segments = path_segments.strip_prefix(base_segments.as_slice())?;
|
||||
Some(
|
||||
relative_segments
|
||||
.iter()
|
||||
.map(|segment| decode_uri_path(segment))
|
||||
.collect::<Vec<_>>()
|
||||
.join("/"),
|
||||
)
|
||||
}
|
||||
|
||||
/// Lexically resolves native absolute or relative path text against this URI.
|
||||
///
|
||||
/// Path text is interpreted using the POSIX or Windows convention inferred
|
||||
|
||||
Reference in New Issue
Block a user