Skip to content

Commit

Permalink
Fixed race condition in minio url.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c committed Jan 19, 2024
1 parent 5f6e46f commit 9612783
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,17 @@ public String getFileSignedUrl(String name) {
return "";
}

// Value copied to prevent race condition in substring
String mUrl = this.minioUrl, mBucket = this.minioBucketId;
// Trim last '/' if present
if (this.minioUrl.charAt(this.minioUrl.length() - 1) == '/') {
this.minioUrl = this.minioUrl.substring(0, this.minioUrl.length() - 1);
if (mUrl.charAt(mUrl.length() - 1) == '/') {
mUrl = mUrl.substring(0, mUrl.length() - 1);
}
if (this.minioBucketId.charAt(this.minioBucketId.length() - 1) == '/') {
this.minioBucketId = this.minioBucketId.substring(0, this.minioBucketId.length() - 1);
if (mBucket.charAt(mBucket.length() - 1) == '/') {
mBucket = mBucket.substring(0, mBucket.length() - 1);
}

// For public files {cdn_url}/{bucket}/{filename} can be directly accessed
return String.format("%s/%s/%s", this.minioUrl, this.minioBucketId, name);
return String.format("%s/%s/%s", mUrl, mBucket, name);
}

/**
Expand Down

0 comments on commit 9612783

Please sign in to comment.