File helper functions for OpenRelik workers
(Elixir port of openrelik_worker_common.file_utils).
Summary
Functions
Creates the original file tree structure from a list of %OutputFile{} structs.
Counts the number of lines in a file using wc -l.
Creates and returns an %OutputFile{} struct.
Deletes a temporary file tree folder structure created by build_file_tree/2.
Converts a full path to a relative path without the root anchor.
Checks if inputfile is a disk image based on its "display_name" extension.
Generates a 32-character lowercase hexadecimal UUIDv4 string (uuid4().hex).
Functions
@spec build_file_tree(Path.t(), list()) :: OpenrelikWorkerCommon.FileUtils.TemporaryDirectory.t() | nil
Creates the original file tree structure from a list of %OutputFile{} structs.
Returns a %TemporaryDirectory{} representing the root path of the file tree, or nil
if files is empty or contains non-%OutputFile{} elements.
@spec count_file_lines(Path.t()) :: non_neg_integer()
Counts the number of lines in a file using wc -l.
@spec create_output_file(String.t(), keyword() | map()) :: OpenrelikWorkerCommon.FileUtils.OutputFile.t()
Creates and returns an %OutputFile{} struct.
Parameters
output_base_path- The path to the output directory.opts- Keyword list or map of optional parameters::display_name- The name of the output file (optional, defaults to generated UUID).:extension- File extension (optional).:data_type- The data type of the output file (optional).:original_path- The original path of the file (optional).:source_file_id- TheOutputFileor ID this file belongs to (optional).:register_in_db- Whether the mediator should create a DB row for this file (defaulttrue).:uuid- Optional override for the generated UUIDv4 hex string.:uuid_generator- Optional0-arity function returning a UUID hex string (for testing).
@spec delete_file_tree(OpenrelikWorkerCommon.FileUtils.TemporaryDirectory.t()) :: :ok
Deletes a temporary file tree folder structure created by build_file_tree/2.
Raises ArgumentError if root_path is not a %TemporaryDirectory{} struct.
Converts a full path to a relative path without the root anchor.
Checks if inputfile is a disk image based on its "display_name" extension.
Raises RuntimeError if "display_name" is not present in inputfile.
@spec uuid4_hex() :: String.t()
Generates a 32-character lowercase hexadecimal UUIDv4 string (uuid4().hex).