Skip to content

Commit

Permalink
make_bucket_versioned method (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant authored Nov 15, 2023
1 parent 2c07450 commit 9494426
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,17 @@ async def _is_bucket_versioned(self, bucket):

is_bucket_versioned = sync_wrapper(_is_bucket_versioned)

async def _make_bucket_versioned(self, bucket, versioned: bool = True):
"""Set bucket versioning status"""
status = "Enabled" if versioned else "Suspended"
return await self._call_s3(
"put_bucket_versioning",
Bucket=bucket,
VersioningConfiguration={"Status": status},
)

make_bucket_versioned = sync_wrapper(_make_bucket_versioned)

async def _rm_versioned_bucket_contents(self, bucket):
"""Remove a versioned bucket and all contents"""
await self.set_session()
Expand Down Expand Up @@ -2294,7 +2305,7 @@ def commit(self):
if self.buffer is not None:
logger.debug("Empty file committed %s" % self)
self._abort_mpu()
write_result = self.fs.touch(self.path)
write_result = self.fs.touch(self.path, **self.kwargs)
elif not self.parts:
if self.buffer is not None:
logger.debug("One-shot upload of %s" % self)
Expand Down
9 changes: 9 additions & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2729,3 +2729,12 @@ def test_cache_handles_find_with_maxdepth(s3):
assert base_name + "/dir1/fileB" not in f

s3.invalidate_cache()


def test_bucket_versioning(s3):
s3.mkdir("maybe_versioned")
assert not s3.is_bucket_versioned("maybe_versioned")
s3.make_bucket_versioned("maybe_versioned")
assert s3.is_bucket_versioned("maybe_versioned")
s3.make_bucket_versioned("maybe_versioned", False)
assert not s3.is_bucket_versioned("maybe_versioned")

0 comments on commit 9494426

Please sign in to comment.