fix: avoid expanding paths for non-regular URLs

This commit is contained in:
sxyazi 2023-11-18 11:28:54 +08:00
parent f3e45d4a47
commit 27255b22de
No known key found for this signature in database
4 changed files with 14 additions and 13 deletions

View file

@ -19,11 +19,11 @@ pub struct Boot {
impl Boot {
fn parse_entry(entry: Option<PathBuf>) -> (PathBuf, Option<OsString>) {
let Some(entry) = entry else {
return (env::current_dir().unwrap(), None);
let entry = match entry {
Some(p) => expand_path(p),
None => return (env::current_dir().unwrap(), None),
};
let entry = expand_path(entry);
let parent = entry.parent();
if parent.is_none() || entry.is_dir() {
return (entry, None);

View file

@ -14,10 +14,12 @@ pub struct Opt {
impl From<&Exec> for Opt {
fn from(e: &Exec) -> Self {
Self {
target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))),
interactive: e.named.contains_key("interactive"),
let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or(""));
if target.is_regular() {
target.set_path(expand_path(&target))
}
Self { target, interactive: e.named.contains_key("interactive") }
}
}
impl From<Url> for Opt {

View file

@ -9,7 +9,12 @@ pub struct Opt {
impl From<&Exec> for Opt {
fn from(e: &Exec) -> Self {
Self { target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))) }
let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or(""));
if target.is_regular() {
target.set_path(expand_path(&target))
}
Self { target }
}
}
impl From<Url> for Opt {

View file

@ -38,12 +38,6 @@ fn _expand_path(p: &Path) -> PathBuf {
#[inline]
pub fn expand_path(p: impl AsRef<Path>) -> PathBuf { _expand_path(p.as_ref()) }
#[inline]
pub fn expand_url(mut u: Url) -> Url {
u.set_path(_expand_path(&u));
u
}
#[inline]
pub fn ends_with_slash(p: &Path) -> bool {
// TODO: uncomment this when Rust 1.74 is released