Skip to content

Commit

Permalink
allow getting files from root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
KristerV committed Nov 20, 2024
1 parent c238280 commit 5bbd899
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/azure_storage/azure_file_share.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule AzureStorage.FileShare do
end

@doc """
The Create Share operation creates a new share under the specified account.
The Create Share operation creates a new share under the specified account.
If the share with the same name already exists, the operation fails.
"""
def create_share(%Context{service: "file"} = context, share) do
Expand All @@ -41,7 +41,7 @@ defmodule AzureStorage.FileShare do
end

@doc """
The Delete Share operation marks the specified share or share snapshot for deletion.
The Delete Share operation marks the specified share or share snapshot for deletion.
The share or share snapshot and any files contained within it are later deleted during garbage collection.
"""
def delete_share(%Context{service: "file"} = context, share) do
Expand Down Expand Up @@ -205,7 +205,7 @@ defmodule AzureStorage.FileShare do
```
context |> AzureStorage.FileShare.get_file("fileshare1", "directory1", "file1")
{:ok,
content,
content,
%{
"Content-Type" => "application/json",
"Content-Length" => "20000",
Expand All @@ -219,12 +219,21 @@ defmodule AzureStorage.FileShare do
@spec get_file(Context.t(), String.t(), String.t(), String.t()) ::
{:ok, binary(), map()} | {:error, String.t()}
def get_file(%Context{service: "file"} = context, share, directory, filename) do
path = "#{share}/#{directory}/#{filename}"
cond do
is_nil(share) or share == "" ->
{:error, "missing_share"}

context
|> build(method: :get, path: path)
|> request(response_body: :full)
|> parse_body_headers_response()
is_nil(filename) or filename == "" ->
{:error, "missing_filename"}

true ->
path = Path.join([share, directory || "", filename])

context
|> build(method: :get, path: path)
|> request(response_body: :full)
|> parse_body_headers_response()
end
end

# helpers
Expand Down

0 comments on commit 5bbd899

Please sign in to comment.