AssetReaderError: move from PathBuf to String
This commit is contained in:
parent
2a48d7c3c8
commit
da9ecbc4ed
@ -38,7 +38,7 @@ impl AssetReader for FileAssetReader {
|
|||||||
let full_path = self.root_path.join(path);
|
let full_path = self.root_path.join(path);
|
||||||
File::open(&full_path).await.map_err(|e| {
|
File::open(&full_path).await.map_err(|e| {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound {
|
if e.kind() == std::io::ErrorKind::NotFound {
|
||||||
AssetReaderError::NotFound(full_path)
|
AssetReaderError::NotFound(full_path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
} else {
|
} else {
|
||||||
e.into()
|
e.into()
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ impl AssetReader for FileAssetReader {
|
|||||||
let full_path = self.root_path.join(meta_path);
|
let full_path = self.root_path.join(meta_path);
|
||||||
File::open(&full_path).await.map_err(|e| {
|
File::open(&full_path).await.map_err(|e| {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound {
|
if e.kind() == std::io::ErrorKind::NotFound {
|
||||||
AssetReaderError::NotFound(full_path)
|
AssetReaderError::NotFound(full_path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
} else {
|
} else {
|
||||||
e.into()
|
e.into()
|
||||||
}
|
}
|
||||||
@ -92,7 +92,9 @@ impl AssetReader for FileAssetReader {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound {
|
if e.kind() == std::io::ErrorKind::NotFound {
|
||||||
Err(AssetReaderError::NotFound(full_path))
|
Err(AssetReaderError::NotFound(
|
||||||
|
full_path.to_path_buf().to_str().unwrap().to_owned(),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err(e.into())
|
Err(e.into())
|
||||||
}
|
}
|
||||||
@ -102,9 +104,9 @@ impl AssetReader for FileAssetReader {
|
|||||||
|
|
||||||
async fn is_directory<'a>(&'a self, path: &'a Path) -> Result<bool, AssetReaderError> {
|
async fn is_directory<'a>(&'a self, path: &'a Path) -> Result<bool, AssetReaderError> {
|
||||||
let full_path = self.root_path.join(path);
|
let full_path = self.root_path.join(path);
|
||||||
let metadata = full_path
|
let metadata = full_path.metadata().map_err(|_e| {
|
||||||
.metadata()
|
AssetReaderError::NotFound(path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
.map_err(|_e| AssetReaderError::NotFound(path.to_owned()))?;
|
})?;
|
||||||
Ok(metadata.file_type().is_dir())
|
Ok(metadata.file_type().is_dir())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -294,7 +294,9 @@ impl AssetReader for MemoryAssetReader {
|
|||||||
data,
|
data,
|
||||||
bytes_read: 0,
|
bytes_read: 0,
|
||||||
})
|
})
|
||||||
.ok_or_else(|| AssetReaderError::NotFound(path.to_path_buf()))
|
.ok_or_else(|| {
|
||||||
|
AssetReaderError::NotFound(path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
|
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
|
||||||
@ -304,7 +306,9 @@ impl AssetReader for MemoryAssetReader {
|
|||||||
data,
|
data,
|
||||||
bytes_read: 0,
|
bytes_read: 0,
|
||||||
})
|
})
|
||||||
.ok_or_else(|| AssetReaderError::NotFound(path.to_path_buf()))
|
.ok_or_else(|| {
|
||||||
|
AssetReaderError::NotFound(path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_directory<'a>(
|
async fn read_directory<'a>(
|
||||||
@ -317,7 +321,9 @@ impl AssetReader for MemoryAssetReader {
|
|||||||
let stream: Box<PathStream> = Box::new(DirStream::new(dir));
|
let stream: Box<PathStream> = Box::new(DirStream::new(dir));
|
||||||
stream
|
stream
|
||||||
})
|
})
|
||||||
.ok_or_else(|| AssetReaderError::NotFound(path.to_path_buf()))
|
.ok_or_else(|| {
|
||||||
|
AssetReaderError::NotFound(path.to_path_buf().to_str().unwrap().to_owned())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn is_directory<'a>(&'a self, path: &'a Path) -> Result<bool, AssetReaderError> {
|
async fn is_directory<'a>(&'a self, path: &'a Path) -> Result<bool, AssetReaderError> {
|
||||||
|
|||||||
@ -38,8 +38,8 @@ use thiserror::Error;
|
|||||||
#[derive(Error, Debug, Clone)]
|
#[derive(Error, Debug, Clone)]
|
||||||
pub enum AssetReaderError {
|
pub enum AssetReaderError {
|
||||||
/// Path not found.
|
/// Path not found.
|
||||||
#[error("Path not found: {}", _0.display())]
|
#[error("Path not found: {}", _0)]
|
||||||
NotFound(PathBuf),
|
NotFound(alloc::string::String),
|
||||||
|
|
||||||
/// Encountered an I/O error while loading an asset.
|
/// Encountered an I/O error while loading an asset.
|
||||||
#[error("Encountered an I/O error while loading asset: {0}")]
|
#[error("Encountered an I/O error while loading asset: {0}")]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use alloc::{borrow::ToOwned, boxed::Box, sync::Arc, vec::Vec};
|
|||||||
use async_lock::RwLockReadGuardArc;
|
use async_lock::RwLockReadGuardArc;
|
||||||
use core::{pin::Pin, task::Poll};
|
use core::{pin::Pin, task::Poll};
|
||||||
use futures_io::AsyncRead;
|
use futures_io::AsyncRead;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{AsyncSeekForward, ErasedAssetReader};
|
use super::{AsyncSeekForward, ErasedAssetReader};
|
||||||
@ -43,9 +43,9 @@ impl ProcessorGatedReader {
|
|||||||
path: &AssetPath<'static>,
|
path: &AssetPath<'static>,
|
||||||
) -> Result<RwLockReadGuardArc<()>, AssetReaderError> {
|
) -> Result<RwLockReadGuardArc<()>, AssetReaderError> {
|
||||||
let infos = self.processor_data.asset_infos.read().await;
|
let infos = self.processor_data.asset_infos.read().await;
|
||||||
let info = infos
|
let info = infos.get(path).ok_or_else(|| {
|
||||||
.get(path)
|
AssetReaderError::NotFound(PathBuf::from(path.path()).to_str().unwrap().to_owned())
|
||||||
.ok_or_else(|| AssetReaderError::NotFound(path.path().to_owned()))?;
|
})?;
|
||||||
Ok(info.file_transaction_lock.read_arc().await)
|
Ok(info.file_transaction_lock.read_arc().await)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,9 @@ impl AssetReader for ProcessorGatedReader {
|
|||||||
match process_result {
|
match process_result {
|
||||||
ProcessStatus::Processed => {}
|
ProcessStatus::Processed => {}
|
||||||
ProcessStatus::Failed | ProcessStatus::NonExistent => {
|
ProcessStatus::Failed | ProcessStatus::NonExistent => {
|
||||||
return Err(AssetReaderError::NotFound(path.to_owned()));
|
return Err(AssetReaderError::NotFound(
|
||||||
|
path.to_path_buf().to_str().unwrap().to_owned(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trace!("Processing finished with {asset_path}, reading {process_result:?}",);
|
trace!("Processing finished with {asset_path}, reading {process_result:?}",);
|
||||||
@ -81,7 +83,9 @@ impl AssetReader for ProcessorGatedReader {
|
|||||||
match process_result {
|
match process_result {
|
||||||
ProcessStatus::Processed => {}
|
ProcessStatus::Processed => {}
|
||||||
ProcessStatus::Failed | ProcessStatus::NonExistent => {
|
ProcessStatus::Failed | ProcessStatus::NonExistent => {
|
||||||
return Err(AssetReaderError::NotFound(path.to_owned()));
|
return Err(AssetReaderError::NotFound(
|
||||||
|
path.to_path_buf().to_str().unwrap().to_owned(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trace!("Processing finished with {process_result:?}, reading meta for {asset_path}",);
|
trace!("Processing finished with {process_result:?}, reading meta for {asset_path}",);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user