feat(bootstrap): improve bucket creation and error handling logic
Enhance the bucket creation process in `BootstrapManager` to handle existing buckets gracefully. Adds logic to reuse the default template when a bucket already exists and ensures proper path formatting before creation. This improves reliability and prevents redundant bucket creation errors.
This commit is contained in:
parent
205cd13b49
commit
0330b8fdb8
1 changed files with 21 additions and 8 deletions
|
|
@ -397,11 +397,24 @@ impl BootstrapManager {
|
|||
info!("Uploading template {} to Drive bucket {}", bot_name, bucket);
|
||||
if operator.stat(&bucket).await.is_err() {
|
||||
info!("Bucket {} not found, creating it", bucket);
|
||||
operator.create_dir("/").await?;
|
||||
let bucket_path = if bucket.ends_with('/') { bucket.clone() } else { format!("{}/", bucket) };
|
||||
match operator.create_dir(&bucket_path).await {
|
||||
Ok(_) => {
|
||||
debug!("Bucket {} created successfully", bucket);
|
||||
}
|
||||
self.upload_directory_recursive(&operator, &path, &bucket)
|
||||
.await?;
|
||||
Err(e) => {
|
||||
let err_msg = format!("{}", e);
|
||||
if err_msg.contains("BucketAlreadyOwnedByYou") {
|
||||
log::warn!("Bucket {} already exists, reusing default.gbai", bucket);
|
||||
self.upload_directory_recursive(&operator, &Path::new("templates/default.gbai"), "default.gbai").await?;
|
||||
continue;
|
||||
} else {
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.upload_directory_recursive(&operator, &path, &bucket).await?;
|
||||
info!("Uploaded template {} to Drive bucket {}", bot_name, bucket);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue