Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Update local_file_write_text function #24

Open
SimonLab opened this issue May 24, 2022 · 1 comment
Open

Update local_file_write_text function #24

SimonLab opened this issue May 24, 2022 · 1 comment
Labels
awaiting-review An issue or pull request that needs to be reviewed enhancement New feature or request help wanted Extra attention is needed T25m Time Estimate 25 Minutes

Comments

@SimonLab
Copy link
Member

The current definition:

gitea/lib/gitea.ex

Lines 196 to 208 in 26ee43a

@doc """
`local_file_write_text/3` writes the desired `text`,
to the `file_name` in the `repo_name`.
Touches the file in case it doesn't already exist.
"""
@spec local_file_write_text(String.t(), String.t(), String.t(), String.t()) ::
:ok | {:error, any}
def local_file_write_text(org_name, repo_name, file_name, text) do
file_path = Path.join([local_repo_path(org_name, repo_name), file_name])
Logger.info("attempting to write to #{file_path}")
File.touch!(file_path)
File.write(file_path, text)
end

can be simplify by removing the File.touch! as File.write will create the file if it doesn't exist, see https://hexdocs.pm/elixir/1.13/File.html#write/3

  @doc """
  `local_file_write_text/3` writes the desired `text`,
  to the `file_name` in the `repo_name`.
  """
  @spec local_file_write_text(String.t(), String.t(), String.t(), String.t()) ::
          :ok | {:error, any}
  def local_file_write_text(org_name, repo_name, file_name, text) do
    file_path = local_repo_path(org_name, repo_name)
                     |> Path.join(file_name)

    Logger.info("attempting to write to #{file_path}")
    File.write(file_path, text)
  end
@SimonLab SimonLab added enhancement New feature or request T25m Time Estimate 25 Minutes labels May 24, 2022
@nelsonic
Copy link
Member

@SimonLab perfect. Let's update it to simplify. 👍

@nelsonic nelsonic added the help wanted Extra attention is needed label May 24, 2022
SimonLab added a commit that referenced this issue May 24, 2022
Create custom exception to return in the function calls

related to: #24 #25
@SimonLab SimonLab added the awaiting-review An issue or pull request that needs to be reviewed label May 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting-review An issue or pull request that needs to be reviewed enhancement New feature or request help wanted Extra attention is needed T25m Time Estimate 25 Minutes
Projects
None yet
Development

No branches or pull requests

2 participants