mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 21:23:05 +00:00
Support creating asset directories (#16220)
# Objective Exposes a means to create an asset directory (and its parent directories). Wasn't sure whether we also wanted the variant to create directories without the parent (i.e. `mkdir` instead of `mkdir -p`)? Fixes https://github.com/bevyengine/bevy_editor_prototypes/issues/144
This commit is contained in:
parent
817f160d35
commit
7740c0f879
3 changed files with 30 additions and 0 deletions
|
@ -164,6 +164,12 @@ impl AssetWriter for FileAssetWriter {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_directory<'a>(&'a self, path: &'a Path) -> Result<(), AssetWriterError> {
|
||||
let full_path = self.root_path.join(path);
|
||||
async_fs::create_dir_all(full_path).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_directory<'a>(&'a self, path: &'a Path) -> Result<(), AssetWriterError> {
|
||||
let full_path = self.root_path.join(path);
|
||||
async_fs::remove_dir_all(full_path).await?;
|
||||
|
|
|
@ -205,6 +205,12 @@ impl AssetWriter for FileAssetWriter {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_directory<'a>(&'a self, path: &'a Path) -> Result<(), AssetWriterError> {
|
||||
let full_path = self.root_path.join(path);
|
||||
std::fs::create_dir_all(full_path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_directory<'a>(&'a self, path: &'a Path) -> Result<(), AssetWriterError> {
|
||||
let full_path = self.root_path.join(path);
|
||||
std::fs::remove_dir_all(full_path)?;
|
||||
|
|
|
@ -384,6 +384,12 @@ pub trait AssetWriter: Send + Sync + 'static {
|
|||
old_path: &'a Path,
|
||||
new_path: &'a Path,
|
||||
) -> impl ConditionalSendFuture<Output = Result<(), AssetWriterError>>;
|
||||
/// Creates a directory at the given path, including all parent directories if they do not
|
||||
/// already exist.
|
||||
fn create_directory<'a>(
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
) -> impl ConditionalSendFuture<Output = Result<(), AssetWriterError>>;
|
||||
/// Removes the directory at the given path, including all assets _and_ directories in that directory.
|
||||
fn remove_directory<'a>(
|
||||
&'a self,
|
||||
|
@ -460,6 +466,12 @@ pub trait ErasedAssetWriter: Send + Sync + 'static {
|
|||
old_path: &'a Path,
|
||||
new_path: &'a Path,
|
||||
) -> BoxedFuture<'a, Result<(), AssetWriterError>>;
|
||||
/// Creates a directory at the given path, including all parent directories if they do not
|
||||
/// already exist.
|
||||
fn create_directory<'a>(
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
) -> BoxedFuture<'a, Result<(), AssetWriterError>>;
|
||||
/// Removes the directory at the given path, including all assets _and_ directories in that directory.
|
||||
fn remove_directory<'a>(
|
||||
&'a self,
|
||||
|
@ -523,6 +535,12 @@ impl<T: AssetWriter> ErasedAssetWriter for T {
|
|||
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
|
||||
Box::pin(Self::rename_meta(self, old_path, new_path))
|
||||
}
|
||||
fn create_directory<'a>(
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
|
||||
Box::pin(Self::create_directory(self, path))
|
||||
}
|
||||
fn remove_directory<'a>(
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
|
|
Loading…
Reference in a new issue