Ensure sqlez build succeeds on Windows (#7072)

On Windows, `OsStr` must be a valid
[WTF-8](https://simonsapin.github.io/wtf-8/) sequence, and there are no
safety ways converting from bytes to OsStr in std. So I added
`PathExt::try_from_bytes` and use it in `sqlez`.
This commit is contained in:
白山風露 2024-01-31 03:07:46 +09:00 committed by GitHub
parent 30b9cef5ba
commit 631f885900
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 71 additions and 8 deletions

View file

@ -14,4 +14,5 @@ thread_local = "1.1.4"
lazy_static.workspace = true
parking_lot.workspace = true
futures.workspace = true
util = { path = "../util" }
uuid.workspace = true

View file

@ -1,11 +1,10 @@
use std::{
ffi::OsStr,
os::unix::prelude::OsStrExt,
path::{Path, PathBuf},
sync::Arc,
};
use anyhow::{Context, Result};
use util::paths::PathExt;
use crate::statement::{SqlType, Statement};
@ -299,7 +298,9 @@ impl<T: Bind, const COUNT: usize> Bind for [T; COUNT] {
impl StaticColumnCount for &Path {}
impl Bind for &Path {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
self.as_os_str().as_bytes().bind(statement, start_index)
self.as_os_str()
.as_encoded_bytes()
.bind(statement, start_index)
}
}
@ -321,10 +322,7 @@ impl Column for PathBuf {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let blob = statement.column_blob(start_index)?;
Ok((
PathBuf::from(OsStr::from_bytes(blob).to_owned()),
start_index + 1,
))
PathBuf::try_from_bytes(blob).map(|path| (path, start_index + 1))
}
}