View Source Nerves.Utils.WSL (nerves v1.10.5)

This module contains utility functions to assist in detecting a Windows Subsystem for Linux environment as well as functions to convert paths between the Windows host and Linux.

Summary

Functions

Returns a two item tuple where the first item is a command and the second is the argument list to run a powershell command as administrator in Windows

If the file was created in a temporary location, get the WSL path and delete it. Otherwise return :ok

Executes wslpath with the file and arguments.

Gets a list of fwup devices on a Windows host. This function can be run from within WSL, as it runs a powershell command to get the list and writes it to a temporary file that WSL can access.

Returns a path to the base file name a temporary location in Windows

Returns a two item tuple containing the Windows host path for a file and its WSL counterpart.

Returns true if the WSL utility wslpath is available

Returns an item tuple with the Windows accessible path and whether the path is a temporary location or original location

Returns true if the path is accessible in Windows

Returns true if inside a WSL shell environment

Returns true when the path matches various kinds of Windows-specific paths, like

Returns true if the path is not a Windows path

Functions

Link to this function

admin_powershell_command(command, args)

View Source
@spec admin_powershell_command(String.t(), String.t()) :: {String.t(), [String.t()]}

Returns a two item tuple where the first item is a command and the second is the argument list to run a powershell command as administrator in Windows

Link to this function

cleanup_file(file, arg2)

View Source
@spec cleanup_file(String.t(), :temporary_location | :original_location) ::
  :ok | {:error, atom()}

If the file was created in a temporary location, get the WSL path and delete it. Otherwise return :ok

Link to this function

execute_wslpath(file, arguments)

View Source
@spec execute_wslpath(String.t(), [String.t()]) :: String.t() | nil

Executes wslpath with the file and arguments.

When a valid WSL path is passed through to wslpath asking for a valid path an "Invalid argument" error is returned. This function catches this error and returns the valid path.

@spec get_fwup_devices() :: {Collectable.t(), exit_status :: non_neg_integer()}

Gets a list of fwup devices on a Windows host. This function can be run from within WSL, as it runs a powershell command to get the list and writes it to a temporary file that WSL can access.

Link to this function

get_temp_file_location(file)

View Source
@spec get_temp_file_location(String.t()) :: String.t()

Returns a path to the base file name a temporary location in Windows

Link to this function

get_wsl_paths(file, use_wslpath)

View Source
@spec get_wsl_paths(String.t(), boolean()) :: {String.t() | nil, String.t() | nil}

Returns a two item tuple containing the Windows host path for a file and its WSL counterpart.

If the path is not available in either Windows or WSL, nil will replace the item

Examples

iex> Nerves.Utils.WSL.get_wsl_paths("mix.exs", Nerves.Utils.WSL.has_wslpath?())
{"C:\Users\username\src\nerves\mix.exs",
"/mnt/c/Users/username/src/nerves/mix.exs"}
@spec has_wslpath?() :: boolean()

Returns true if the WSL utility wslpath is available

Link to this function

make_file_accessible(file, is_wsl, has_wslpath)

View Source
@spec make_file_accessible(String.t(), boolean(), boolean()) ::
  {String.t(), :original_location} | {String.t(), :temporary_location}

Returns an item tuple with the Windows accessible path and whether the path is a temporary location or original location

Link to this function

path_accessible_in_windows?(file, use_wslpath)

View Source
@spec path_accessible_in_windows?(String.t(), boolean()) :: boolean()

Returns true if the path is accessible in Windows

@spec running_on_wsl?() :: boolean()

Returns true if inside a WSL shell environment

Link to this function

valid_windows_path?(path)

View Source
@spec valid_windows_path?(String.t()) :: boolean()

Returns true when the path matches various kinds of Windows-specific paths, like:

C:\
C:\projects
\\myserver\sharename\
\\wsl$\Ubuntu-18.04\home\username\my_project\
@spec valid_wsl_path?(String.t()) :: boolean()

Returns true if the path is not a Windows path