~zethra/stargazer

e66961be189c31e3a0b2b60330d3853e00f81756 — Ben Aaron Goldberg 11 days ago 5478c33 + cc1ad71
Merge branch 'f/windows-non-utf8-paths'
3 files changed, 11 insertions(+), 20 deletions(-)

M Cargo.lock
M Cargo.toml
M src/get_file.rs
M Cargo.lock => Cargo.lock +7 -0
@@ 675,6 675,12 @@ dependencies = [
]

[[package]]
name = "os_str_bytes"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d"

[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1019,6 1025,7 @@ dependencies = [
 "net2",
 "num_cpus",
 "once_cell",
 "os_str_bytes",
 "percent-encoding",
 "rcgen",
 "regex",

M Cargo.toml => Cargo.toml +1 -0
@@ 60,6 60,7 @@ users = "0.11"
cfg-if = "1.0"
libc = "0.2"
net2 = "0.2"
os_str_bytes = "3.1"

[dependencies.chrono]
version = "0.4"

M src/get_file.rs => src/get_file.rs +3 -20
@@ 22,6 22,7 @@ use async_net::TcpStream;
use async_rustls::server::TlsStream;
use blocking::unblock;
use futures_lite::io::{AsyncReadExt, AsyncWriteExt};
use os_str_bytes::OsStringBytes;
use percent_encoding::percent_decode_str;
use std::{ffi::OsString, path::Path};



@@ 122,32 123,14 @@ pub async fn get_file<'a>(
    Ok(())
}

#[cfg(unix)]
pub fn parse_path(percent_encoded: &str) -> Result<OsString> {
    let mut bytes: Vec<u8> = percent_decode_str(percent_encoded).collect();
    // Remove leading slashes if present
    while !bytes.is_empty() && bytes[0] == b'/' {
        bytes.remove(0);
    }

    // TODO windows support
    use std::os::unix::ffi::OsStringExt;
    Ok(OsString::from_vec(bytes))
}

#[cfg(not(unix))]
pub fn parse_path(percent_encoded: &str) -> Result<OsString> {
    let mut bytes: Vec<u8> = percent_decode_str(percent_encoded).collect();
    // Remove leading slash if present
    while !bytes.is_empty() && bytes[0] == b'/' {
        bytes.remove(0);
    }

    use std::ffi::OsStr;
    Ok(OsStr::new(
        std::str::from_utf8(&bytes).context("File path is not valid UTF-8")?,
    )
    .to_owned())
    Ok(OsString::from_raw_vec(bytes)
        .context("File path is not a valid encoding for your OS platform")?)
}

fn get_mime_type(path: &Path) -> String {