module

Hwaro::Utils::OutputGuard

Instance methods

safe_output_path(output_path : String, output_dir : String, cwd : String = Dir.current) : String | Nil

Verify that the given output path is within the output directory. Returns the output_path if safe, or a fallback path and logs a warning.

Example: safe_path("public/../etc/passwd", "public") # => "public/index.html" (with warning) safe_path("public/blog/index.html", "public") # => "public/blog/index.html"

cwd lets a caller that resolves many paths in one build pass the working directory it already holds.

Source
safe_to_delete_directory?(path : String, output_dir : String) : Bool

Check an existing directory before pruning it. Resolve the directory itself (including symlinked ancestors), reject a symlink leaf, and never allow pruning the output root.

Source
safe_to_delete_file?(path : String, output_dir : String) : Bool

Check an existing file before unlinking it. Lexical containment alone is not enough for a persisted stale path such as public/link/secret: public/link may point outside the output tree. The leaf may itself be a symlink because deleting it removes the link, so resolve and check its parent instead.

Source
within_output_dir?(output_path : String, output_dir : String) : Bool

Check if a path is within the output directory.

Source