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:
parent
c079d6e452
commit
aec4411be8
1 changed files with 8 additions and 6 deletions
|
|
@ -365,17 +365,21 @@ impl BootstrapManager {
|
||||||
{
|
{
|
||||||
let bot_name = path.file_name().unwrap().to_string_lossy().to_string();
|
let bot_name = path.file_name().unwrap().to_string_lossy().to_string();
|
||||||
let bucket = bot_name.trim_start_matches('/').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
|
// Check if bucket exists
|
||||||
if client.head_bucket().bucket(&bucket).send().await.is_err() {
|
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()
|
match client.create_bucket()
|
||||||
.bucket(&bucket)
|
.bucket(&bucket)
|
||||||
.send()
|
.send()
|
||||||
.await {
|
.await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
debug!("Bucket {} created successfully", bucket);
|
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) => {
|
Err(e) => {
|
||||||
error!("Failed to create bucket {}: {:?}", bucket, 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(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue