diff --git a/crates/bevy_asset/src/io/file/file_asset.rs b/crates/bevy_asset/src/io/file/file_asset.rs index 3c20702167..a7af0197e2 100644 --- a/crates/bevy_asset/src/io/file/file_asset.rs +++ b/crates/bevy_asset/src/io/file/file_asset.rs @@ -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?; diff --git a/crates/bevy_asset/src/io/file/sync_file_asset.rs b/crates/bevy_asset/src/io/file/sync_file_asset.rs index 5887724736..cadea49492 100644 --- a/crates/bevy_asset/src/io/file/sync_file_asset.rs +++ b/crates/bevy_asset/src/io/file/sync_file_asset.rs @@ -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)?; diff --git a/crates/bevy_asset/src/io/mod.rs b/crates/bevy_asset/src/io/mod.rs index eceefb2e7a..207e51659b 100644 --- a/crates/bevy_asset/src/io/mod.rs +++ b/crates/bevy_asset/src/io/mod.rs @@ -384,6 +384,12 @@ pub trait AssetWriter: Send + Sync + 'static { old_path: &'a Path, new_path: &'a Path, ) -> impl ConditionalSendFuture>; + /// 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>; /// 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 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,