Skip to content

Commit

Permalink
fix: check bucket existence by creating a dummy file
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Sep 10, 2024
1 parent 7a5a9e9 commit 4bb4c2e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ObjectStorageSession {
.map_err(|error| anyhow!("failed to initialize object storage bucket client: {error}"))?
.with_path_style();

if bucket.get_object("/").await.is_err() {
if check_bucket_exists(&bucket).await {
if bucket_create {
let config = BucketConfiguration::private();
let response = Bucket::create_with_path_style(
Expand Down Expand Up @@ -304,6 +304,18 @@ impl SessionTask {
}
}

async fn check_bucket_exists(bucket: &Bucket) -> bool {
const TEST_FILE: &'static str = "/_sos_bucket_test";

match bucket.put_object(TEST_FILE, TEST_FILE.as_bytes()).await {
Ok(_) => {
bucket.delete_object(TEST_FILE).await.ok();
true
}
Err(_) => false,
}
}

async fn cleanup(bucket: Bucket) -> Result<()> {
info!("Cleaning up...");

Expand Down

0 comments on commit 4bb4c2e

Please sign in to comment.