refactor(priv): move is_root into util.priv for reuse
Author:
Chris Tusa <chris.tusa@leafscale.com>
Date:
Jul 05, 2026 17:09
Changeset:
026265f1ae95cbd1304ff1c8cf324323d188264f
Branch:
default
Changed files:
Diff
diff -r 6c9f23477328 -r 026265f1ae95 src/main.reef --- a/src/main.reef Sun Jul 05 17:04:52 2026 -0500 +++ b/src/main.reef Sun Jul 05 17:09:01 2026 -0500 @@ -42,6 +42,7 @@ import commands.ports as cmd_ports import commands.verify as cmd_verify import util.color +import util.priv fn version(): string return "0.4.2" @@ -153,20 +154,6 @@ return opts end parse_global_options -// Check if we are running as root (UID 0) -// Uses file test to check write permission on system directory -fn is_root(): bool - // Try to create a temp file in /var/lib/coral - only root can write there - let test_file = "/var/lib/coral/.root_check" - if file.writeFile(test_file, "1") - // Successfully wrote - we have root-level access - // File will be overwritten next time, no need to delete - return true - end if - return false -end is_root - - // Check if a command is a query command (doesn't require root) fn is_query_command(cmd: string): bool // Query commands that don't modify the system @@ -233,7 +220,7 @@ // Check for root privileges if required if not is_query_command(cmd) - if not is_root() + if not priv.is_root() color.print_error("This command requires root privileges") println("Run 'coral " + cmd + "' as root or with sudo") return ec.EXIT_ROOT_REQUIRED() diff -r 6c9f23477328 -r 026265f1ae95 src/util/priv.reef --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/util/priv.reef Sun Jul 05 17:09:01 2026 -0500 @@ -0,0 +1,40 @@ +/****************************************************************************** + __ ____ __ + / / ___ ____ _/ __/_____________ _/ /__ + / / / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \ + / /___/ __/ /_/ / __(__ ) /__/ /_/ / / __/ + /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/ + + (C)opyright 2025, Leafscale, LLC - https://www.leafscale.com + + Project: Zygaena + Filename: priv.reef + Authors: Chris Tusa <chris.tusa@leafscale.com> + License: <see LICENSE file included with this source code> +Description: Privilege detection helpers + +******************************************************************************/ + +module util.priv + +import io.file + +export + // Check if we are running as root (UID 0) + fn is_root(): bool +end export + +// Check if we are running as root (UID 0) +// Uses file test to check write permission on system directory +fn is_root(): bool + // Try to create a temp file in /var/lib/coral - only root can write there + let test_file = "/var/lib/coral/.root_check" + if file.writeFile(test_file, "1") + // Successfully wrote - we have root-level access + // File will be overwritten next time, no need to delete + return true + end if + return false +end is_root + +end module