Skip to content

Commit

Permalink
Try #297:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jun 29, 2023
2 parents af07347 + 78ddbf4 commit 6c4e9b6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- v0.11.0: The `s3_exists` and `isdir(::S3Path)` calls no longer encounter HTTP 403 (Access Denied) errors when attempting to list resources which requiring an `s3:prefix` to be specified ([#289]).
- v0.11.1: The new keyword argument `returns` for `Base.write(fp::S3Path, ...)` determines the output returned from `write`, which can now be the raw `AWS.Response` (`returns=:response`) or the `S3Path` (`returns=:path`); this latter option returns an `S3Path` populated with the version ID of the written object (when versioning is enabled on the bucket) ([#293]).
- v0.11.2: New constructor for unversioned `S3Path` and version: `S3Path(path::S3Path; version=...)` ([#297]).

[#289]: https://github.com/JuliaCloud/AWSS3.jl/pull/289
[#293]: https://github.com/JuliaCloud/AWSS3.jl/pull/293
[#297]: https://github.com/JuliaCloud/AWSS3.jl/pull/297
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AWSS3"
uuid = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
version = "0.11.1"
version = "0.11.2"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down
12 changes: 12 additions & 0 deletions src/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ end

"""
S3Path()
S3Path(path::S3Path; version::$(AbstractS3Version))
S3Path(str; version::$(AbstractS3Version)=nothing, config::$(AbstractS3PathConfig)=nothing)
Construct a new AWS S3 path type which should be of the form
Expand Down Expand Up @@ -107,6 +108,17 @@ function S3Path(
)
end

function S3Path(path::S3Path; version::AbstractS3Version)
if !isnothing(path.version)
throw(
ArgumentError(
"Can't construct versioned path, input already specifies version: $path"
),
)
end
return S3Path(path.bucket, path.key; path.isdirectory, path.config, version)
end

# To avoid a breaking change.
function S3Path(
str::AbstractString;
Expand Down
17 changes: 17 additions & 0 deletions test/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,23 @@ function s3path_tests(base_config)
@test_throws ArgumentError S3Path("s3://my_bucket/"; version="")
end

@testset "construct versioned s3path from unversioned s3path" begin
# Use custom config to test that config is preserved in construction
config = AWSConfig(; region="bogus")
ver = String('A':'Z') * String('0':'5')

unversioned = S3Path("s3://my_bucket/prefix"; config)
@test unversioned.version === nothing

versioned = S3Path(unversioned; version=ver)
@test versioned.version == ver
@test versioned == S3Path("s3://my_bucket/prefix"; version=ver)
@test versioned.config == unversioned.config == config

# If input path already has a version, fail---even if the versions are the same
@test_throws ArgumentError S3Path(versioned; version=ver)
end

# `s3_list_versions` gives `SignatureDoesNotMatch` exceptions on Minio
if is_aws(base_config)
@testset "S3Path versioning" begin
Expand Down

0 comments on commit 6c4e9b6

Please sign in to comment.