diff --git a/assets-updater/src/core/export_pipeline.rs b/assets-updater/src/core/export_pipeline.rs index b4080cc..256be75 100644 --- a/assets-updater/src/core/export_pipeline.rs +++ b/assets-updater/src/core/export_pipeline.rs @@ -59,6 +59,17 @@ pub fn get_hex_index(input: &str) -> String { format!("{:032x}", hash_val) } +pub fn empty_dir(base: PathBuf, name: String) -> PathBuf { + let mut dir = base.join(&name); + let mut cnt = 1; + while dir.exists() { + dir = base.join(format!("{}_{}", &name, cnt)); + cnt += 1; + } + std::fs::create_dir_all(&dir).unwrap(); + dir +} + pub async fn extract_unity_asset_bundle( app_config: &AppConfig, sync_context: &SyncContext, @@ -69,11 +80,13 @@ pub async fn extract_unity_asset_bundle( category: &str, ) -> Result<(PathBuf, bool), ExportPipelineError> { let hash = get_hex_index(export_path); - let output_dir = std::env::temp_dir() - .join("sekai-updater") - .join("extract") - .join(&sync_context.region) - .join(hash); + let output_dir = empty_dir( + std::env::temp_dir() + .join("sekai-updater") + .join("extract") + .join(&sync_context.region), + hash, + ); let Some(asset_studio_cli_path) = app_config.tools.asset_studio_cli_path.as_deref() else { return Ok((asset_bundle_file.parent().unwrap().to_path_buf(), true)); }; diff --git a/server/src/router/download.rs b/server/src/router/download.rs index b29626a..8ce1c6b 100644 --- a/server/src/router/download.rs +++ b/server/src/router/download.rs @@ -86,7 +86,7 @@ pub async fn download( let _ = server_send_files(send_stream, &files).await; } - let _ = std::fs::remove_file(dir); + let _ = std::fs::remove_dir_all(dir); Ok(()) }