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