diff options
author | root <github@bigly.dog> | 2024-04-08 00:47:33 -0700 |
---|---|---|
committer | root <github@bigly.dog> | 2024-04-08 00:51:11 -0700 |
commit | e18572580aaa905c0e49fa3739e5951ed92d7bee (patch) | |
tree | 761cd10ef30ebd0ee87fcb2b43f42f43315965fb | |
parent | 34543753794a423e45af3e0a63360f94eab0f2eb (diff) |
give up on correctly encoding windows
-rw-r--r-- | RELEASE_NOTES.md | 4 | ||||
-rw-r--r-- | src/input.rs | 41 |
2 files changed, 23 insertions, 22 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 291d9f9..5534b85 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,9 @@ ## Good news +v0.4.27 + +- Give up on trying to solve windows edge cases, instead of not working at all, it now works for utf-8 only + v0.4.26 - Reduce allocations diff --git a/src/input.rs b/src/input.rs index 22b52e7..de2031b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -23,8 +23,6 @@ use { #[cfg(target_family = "unix")] use std::os::unix::ffi::OsStringExt; -#[cfg(target_family = "windows")] -use std::os::windows::ffi::OsStringExt; #[derive(Debug)] pub enum RowIn { @@ -133,20 +131,16 @@ async fn stream_patch(patches: &Path) -> impl Stream<Item = Result<RowIn, Die>> Either::Right(stream.try_filter_map(|x| ready(Ok(x)))) } -fn u8_pathbuf(v8: Vec<u8>) -> PathBuf { +#[allow(clippy::unnecessary_wraps)] +fn u8_pathbuf(v8: Vec<u8>) -> Option<PathBuf> { #[cfg(target_family = "unix")] { - PathBuf::from(OsString::from_vec(v8)) + Some(PathBuf::from(OsString::from_vec(v8))) } #[cfg(target_family = "windows")] { - let mut buf = Vec::new(); - for chunk in v8.chunks_exact(2) { - let c: [u8; 2] = chunk.try_into().expect("exact chunks"); - let b = u16::from_ne_bytes(c); - buf.push(b) - } - PathBuf::from(OsString::from_wide(&buf)) + let buf = String::from_utf8(v8).ok()?; + Some(PathBuf::from(OsString::from(buf))) } } @@ -168,17 +162,20 @@ fn stream_stdin(use_nul: bool) -> impl Stream<Item = Result<RowIn, Die>> { match next { None => Ok(None), Some(buf) => { - let path = u8_pathbuf(buf); - match canonicalize(&path).await { - Err(e) if e.kind() == ErrorKind::NotFound => Ok(Some((None, s))), - Err(e) => Err(Die::IO(path, e.kind())), - Ok(canonical) => Ok(Some({ - if s.1.insert(canonical.clone()) { - (Some(RowIn::Entire(canonical)), s) - } else { - (None, s) - } - })), + if let Some(path) = u8_pathbuf(buf) { + match canonicalize(&path).await { + Err(e) if e.kind() == ErrorKind::NotFound => Ok(Some((None, s))), + Err(e) => Err(Die::IO(path, e.kind())), + Ok(canonical) => Ok(Some({ + if s.1.insert(canonical.clone()) { + (Some(RowIn::Entire(canonical)), s) + } else { + (None, s) + } + })), + } + } else { + Ok(Some((None, s))) } } } |