Ensure writable dir

SolidGroundUX DocumentationSolidGroundUX
NL

fn: sgnd_ensure_writable_dir

Purpose

Ensure that a directory exists; adjust ownership when newly created under sudo.

Description

Despite its historical name, this function does not test the directory for write permission.

Arguments

  • $1 — Directory path.

Side effects

May create the directory and attempt to chown it to SUDO_USER.

Returns

  • 0 if the directory exists after the attempt; 2 for empty path, 3 for mkdir failure, 4 if still absent.

Usage

  sgnd_ensure_writable_dir "/tmp/sgnd-example"