From 596946f54c27836aadc2b2009302ff771206dbee Mon Sep 17 00:00:00 2001 From: meteorgan Date: Thu, 26 Sep 2024 17:21:23 +0800 Subject: [PATCH] return unsupport for read/stat/delete when versioning is not enabled --- core/src/services/s3/backend.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index 8073cbfbb92..d60adff15b0 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -958,6 +958,13 @@ impl Access for S3Backend { } async fn stat(&self, path: &str, args: OpStat) -> Result { + if args.version().is_some() && !self.core.enable_versioning { + return Err(Error::new( + ErrorKind::Unsupported, + "the bucket doesn't enable versioning, cannot stat with version", + )); + } + let resp = self.core.s3_head_object(path, args).await?; let status = resp.status(); @@ -994,6 +1001,13 @@ impl Access for S3Backend { } async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { + if args.version().is_some() && !self.core.enable_versioning { + return Err(Error::new( + ErrorKind::Unsupported, + "the bucket doesn't enable versioning, cannot read with version", + )); + } + let resp = self.core.s3_get_object(path, args.range(), &args).await?; let status = resp.status(); @@ -1025,6 +1039,13 @@ impl Access for S3Backend { return Ok(RpDelete::default()); } + if args.version().is_some() && !self.core.enable_versioning { + return Err(Error::new( + ErrorKind::Unsupported, + "the bucket doesn't enable versioning, cannot delete with version", + )); + } + let resp = self.core.s3_delete_object(path, &args).await?; let status = resp.status(); @@ -1043,7 +1064,7 @@ impl Access for S3Backend { if args.version() && !self.core.enable_versioning { return Err(Error::new( ErrorKind::Unsupported, - "the bucket doesn't enable versioning", + "the bucket doesn't enable versioning, cannot list with version", )); }