Skip to content

Commit

Permalink
refactor get_buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk committed Jan 18, 2025
1 parent e47c75b commit 157148c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions src/cas/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,28 @@ impl CasFS {
Ok(())
}

/// Get a list of all buckets in the system.
pub fn get_buckets(&self) -> Result<Vec<Bucket>, MetaError> {
let bucket_tree = match self.sled_bucket_meta_tree() {
Ok(t) => t,
Err(e) => return Err(MetaError::UnknownError(e.to_string())),
};
let buckets = bucket_tree
.scan_prefix([])
.values()
.filter_map(|raw_value| {
let value = match raw_value {
Err(_) => return None,
Ok(v) => v,
};
// unwrap here is fine as it means the db is corrupt
let bucket_meta = BucketMeta::try_from(&*value).expect("Corrupted bucket metadata");
Some(bucket_meta.into())
})
.collect();
Ok(buckets)
}

/// Delete an object from a bucket.
pub async fn delete_object(&self, bucket: &str, object: &str) -> Result<(), sled::Error> {
info!("Deleting object {}", object);
Expand Down Expand Up @@ -435,24 +457,6 @@ impl CasFS {
}
}

/// Get a list of all buckets in the system.
pub fn buckets(&self) -> Result<Vec<Bucket>, sled::Error> {
Ok(self
.sled_bucket_meta_tree()?
.scan_prefix([])
.values()
.filter_map(|raw_value| {
let value = match raw_value {
Err(_) => return None,
Ok(v) => v,
};
// unwrap here is fine as it means the db is corrupt
let bucket_meta = BucketMeta::try_from(&*value).expect("Corrupted bucket metadata");
Some(bucket_meta.into())
})
.collect())
}

/// Save data on the filesystem. A list of block ID's used as keys for the data blocks is
/// returned, along with the hash of the full byte stream, and the length of the stream.
pub async fn store_bytes(&self, data: ByteStream) -> io::Result<(Vec<BlockID>, BlockID, u64)> {
Expand Down
2 changes: 1 addition & 1 deletion src/s3fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl S3 for S3FS {
&self,
_: S3Request<ListBucketsInput>,
) -> S3Result<S3Response<ListBucketsOutput>> {
let csfs_buckets = try_!(self.casfs.buckets());
let csfs_buckets = try_!(self.casfs.get_buckets());
let mut buckets = Vec::with_capacity(csfs_buckets.len());
for bucket in csfs_buckets {
let bucket = Bucket {
Expand Down

0 comments on commit 157148c

Please sign in to comment.