mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-09 08:27:36 +08:00
Fix root directory listing on S3 when empty (#646)
This commit is contained in:
parent
46d49743b9
commit
9da44fd541
2 changed files with 20 additions and 1 deletions
|
@ -70,7 +70,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do
|
|||
delimiter = if recursive, do: nil, else: "/"
|
||||
|
||||
with {:ok, %{keys: keys}} <- list_objects(file_system, prefix: dir_key, delimiter: delimiter) do
|
||||
if keys == [] do
|
||||
if keys == [] and dir_key != "" do
|
||||
FileSystem.Utils.posix_error(:enoent)
|
||||
else
|
||||
paths = keys |> List.delete(dir_key) |> Enum.map(&("/" <> &1))
|
||||
|
|
|
@ -99,6 +99,25 @@ defmodule Livebook.FileSystem.S3Test do
|
|||
assert {:error, "no such file or directory"} = FileSystem.list(file_system, dir_path, false)
|
||||
end
|
||||
|
||||
test "does not return an error when the root directory is empty", %{bypass: bypass} do
|
||||
Bypass.expect_once(bypass, "GET", "/mybucket", fn conn ->
|
||||
assert %{"delimiter" => "/"} = conn.params
|
||||
|
||||
conn
|
||||
|> Plug.Conn.put_resp_content_type("application/xml")
|
||||
|> Plug.Conn.resp(200, """
|
||||
<ListBucketResult>
|
||||
<Name>mybucket</Name>
|
||||
</ListBucketResult>
|
||||
""")
|
||||
end)
|
||||
|
||||
file_system = S3.new(bucket_url(bypass.port), "key", "secret")
|
||||
dir_path = "/"
|
||||
|
||||
assert {:ok, []} = FileSystem.list(file_system, dir_path, false)
|
||||
end
|
||||
|
||||
test "returns a list of absolute child object paths", %{bypass: bypass} do
|
||||
Bypass.expect_once(bypass, "GET", "/mybucket", fn conn ->
|
||||
assert %{"delimiter" => "/"} = conn.params
|
||||
|
|
Loading…
Reference in a new issue