Raxol.System.DeltaUpdaterSystemAdapterBehaviour behaviour (Raxol v0.5.0)

View Source

Behaviour for a system adapter used by DeltaUpdater.

This module defines the contract for functions that interact with the system, allowing for different implementations (e.g., a real one and a mock for tests).

Summary

Callbacks

Gets the current version string.

Changes the mode of a file. Mirrors File.chmod!/2 or File.chmod/2.

Creates a directory, including any necessary parent directories. Mirrors File.mkdir_p!/1 or File.mkdir_p/1.

Removes a file or directory recursively. Mirrors File.rm_rf!/1 or File.rm_rf/1.

Performs a simple HTTP GET request and returns the body as a string.

Performs an HTTP request. Mirrors :httpc.request/4 or similar functionality. method is an atom e.g. :get, :post. url_with_headers is typically {charlist_url, list_of_headers}. http_options and stream_options are keyword lists or lists of tuples.

Gets the operating system type. Mirrors :os.type/0.

Gets the command-line arguments passed to the program. Mirrors System.argv/0.

Executes a system command. Mirrors System.cmd/3. Options can include e.g. :stderr_to_stdout.

Gets the value of an environment variable. Mirrors System.get_env/1.

Gets the path to the system's temporary directory. Mirrors System.tmp_dir!/0 or System.tmp_dir/0.

Replaces the current executable with a new one. This abstracts the call to Raxol.System.Updater.do_replace_executable/3.

Callbacks

current_version()

@callback current_version() :: String.t()

Gets the current version string.

file_chmod(path, mode)

@callback file_chmod(path :: String.t(), mode :: integer()) ::
  :ok | {:error, reason :: atom()}

Changes the mode of a file. Mirrors File.chmod!/2 or File.chmod/2.

file_mkdir_p(path)

@callback file_mkdir_p(path :: String.t()) :: :ok | {:error, reason :: atom()}

Creates a directory, including any necessary parent directories. Mirrors File.mkdir_p!/1 or File.mkdir_p/1.

file_rm_rf(path)

@callback file_rm_rf(path :: String.t()) :: :ok | {:error, reason :: atom()}

Removes a file or directory recursively. Mirrors File.rm_rf!/1 or File.rm_rf/1.

http_get(url)

@callback http_get(url :: String.t()) :: {:ok, String.t()} | {:error, any()}

Performs a simple HTTP GET request and returns the body as a string.

httpc_request(method, url_with_headers, http_options, stream_options)

@callback httpc_request(
  method :: atom(),
  url_with_headers :: {charlist(), list()},
  http_options :: Keyword.t() | list(),
  stream_options :: Keyword.t() | list()
) ::
  {:ok,
   {{http_version :: tuple(), status_code :: integer(),
     reason_phrase :: charlist()}, headers :: list(),
    body :: charlist() | binary()}}
  | {:ok, :saved_to_file}
  | {:error, reason :: any()}

Performs an HTTP request. Mirrors :httpc.request/4 or similar functionality. method is an atom e.g. :get, :post. url_with_headers is typically {charlist_url, list_of_headers}. http_options and stream_options are keyword lists or lists of tuples.

os_type()

@callback os_type() :: {:win32, atom()} | {:unix, atom()}

Gets the operating system type. Mirrors :os.type/0.

system_argv()

@callback system_argv() :: [String.t()]

Gets the command-line arguments passed to the program. Mirrors System.argv/0.

system_cmd(command, args, options)

@callback system_cmd(
  command :: String.t(),
  args :: [String.t()],
  options :: Keyword.t()
) :: {output :: String.t(), exit_status :: integer()}

Executes a system command. Mirrors System.cmd/3. Options can include e.g. :stderr_to_stdout.

system_get_env(varname)

@callback system_get_env(varname :: String.t()) :: String.t() | nil

Gets the value of an environment variable. Mirrors System.get_env/1.

system_tmp_dir()

@callback system_tmp_dir() :: {:ok, String.t()} | {:error, reason :: any()}

Gets the path to the system's temporary directory. Mirrors System.tmp_dir!/0 or System.tmp_dir/0.

updater_do_replace_executable(current_exe, new_exe, platform)

@callback updater_do_replace_executable(
  current_exe :: String.t(),
  new_exe :: String.t(),
  platform :: String.t()
) :: :ok | {:error, reason :: any()}

Replaces the current executable with a new one. This abstracts the call to Raxol.System.Updater.do_replace_executable/3.