Skip to content

Commit

Permalink
Logging: Only call CreateBucket on Amazon S3 when the bucket does not…
Browse files Browse the repository at this point in the history
… already exist. (#924)

Co-authored-by: jjallaire-aisi <[email protected]>
  • Loading branch information
jjallaire and jjallaire-aisi authored Dec 2, 2024
1 parent 9e6646a commit 594f174
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Logging: Only call CreateBucket on Amazon S3 when the bucket does not already exist.
- Improve cancellation feedback and prevent multiple cancellations when using fullscreen display.

## v0.3.48 (01 December 2024)
Expand Down
17 changes: 16 additions & 1 deletion src/inspect_ai/_util/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,22 @@ def rm(
self.fs.rm(path, recursive=recursive, maxdepth=maxdepth)

def mkdir(self, path: str, exist_ok: bool = False) -> None:
self.fs.makedirs(path, exist_ok=exist_ok)
if self.is_s3():
# try to avoid calling create_bucket on s3 filesystems (as that requires distinct
# privileges from being able to write to an existing bucket). we do this by
# first calling mkdir w/ create_parents=False and then only if that fails
# with FileNotFound do we attempt to create the bucket by calling mkdirs
try:
self.fs.makedir(path, create_parents=False)
except FileExistsError:
if exist_ok:
pass
else:
raise
except FileNotFoundError:
self.fs.makedirs(path, exist_ok=exist_ok)
else:
self.fs.makedirs(path, exist_ok=exist_ok)

def info(self, path: str, **kwargs: dict[str, Any]) -> FileInfo:
return self._file_info(self.fs.info(path, **kwargs))
Expand Down

0 comments on commit 594f174

Please sign in to comment.