feat: check bucket existence before uploading templates

Only upload templates to Drive buckets if the bucket was just created. Skip upload if bucket already exists to avoid overwriting existing content.

- Change from always uploading to conditionally uploading based on bucket existence
- Add info log when skipping upload for existing buckets
- Maintain same upload behavior for newly created buckets
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-11-04 07:07:39 -03:00
parent c079d6e452
commit aec4411be8

View file

@ -365,17 +365,21 @@ impl BootstrapManager {
{
let bot_name = path.file_name().unwrap().to_string_lossy().to_string();
let bucket = bot_name.trim_start_matches('/').to_string();
info!("Uploading template {} to Drive bucket {}", bot_name, bucket);
info!("Checking template {} for Drive bucket {}", bot_name, bucket);
// Check if bucket exists
if client.head_bucket().bucket(&bucket).send().await.is_err() {
info!("Bucket {} not found, creating it", bucket);
info!("Bucket {} not found, creating it and uploading template", bucket);
match client.create_bucket()
.bucket(&bucket)
.send()
.await {
Ok(_) => {
debug!("Bucket {} created successfully", bucket);
// Only upload template if bucket was just created
self.upload_directory_recursive(client, &path, &bucket, "/")
.await?;
info!("Uploaded template {} to Drive bucket {}", bot_name, bucket);
}
Err(e) => {
error!("Failed to create bucket {}: {:?}", bucket, e);
@ -385,11 +389,9 @@ impl BootstrapManager {
));
}
}
} else {
info!("Bucket {} already exists, skipping template upload", bucket);
}
self.upload_directory_recursive(client, &path, &bucket, "/")
.await?;
info!("Uploaded template {} to Drive bucket {}", bot_name, bucket);
}
}
Ok(())