Skip to content

Commit

Permalink
remove automatic panicky conversion of potentially binary paths into …
Browse files Browse the repository at this point in the history
…non-binary strings

Issue: #124
  • Loading branch information
eugenesvk committed Dec 4, 2024
1 parent 3978204 commit d7d2187
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ impl TrashContextExtMacos for TrashContext {
}
impl TrashContext {
pub(crate) fn delete_all_canonicalized(&self, full_paths: Vec<PathBuf>) -> Result<(), Error> {
let full_paths = full_paths.into_iter().map(to_string).collect::<Result<Vec<_>, _>>()?;
match self.platform_specific.delete_method {
DeleteMethod::Finder => delete_using_finder(full_paths),
DeleteMethod::NsFileManager => delete_using_file_mgr(full_paths),
DeleteMethod::Finder => delete_using_finder(&full_paths),
DeleteMethod::NsFileManager => delete_using_file_mgr(&full_paths),
}
}
}
Expand Down Expand Up @@ -126,15 +125,6 @@ fn delete_using_finder(full_paths: Vec<String>) -> Result<(), Error> {
Ok(())
}

fn to_string<T: Into<OsString>>(str_in: T) -> Result<String, Error> {
let os_string = str_in.into();
let s = os_string.to_str();
match s {
Some(s) => Ok(s.to_owned()),
None => Err(Error::ConvertOsString { original: os_string }),
}
}

use std::borrow::Cow;
use percent_encoding::percent_encode_byte as b2pc;
fn from_utf8_lossy_pc(v:&[u8]) -> Cow<'_, str> { // std's from_utf8_lossy, but non-utf8 byte sequences are %-encoded instead of being replaced by an special symbol. Valid utf8, including `%`, are not escaped, so this is still lossy. Useful for macOS file paths.
Expand Down

0 comments on commit d7d2187

Please sign in to comment.