Migrate to Reef 0.7.6 Result/Option stdlib API
Migrate to Reef 0.7.6 Result/Option stdlib API Adapt all fallible stdlib calls to the 0.7.5 Result/Option breaking change: file I/O, dir/fs ops (create_dir_all/remove_dir/copy/remove/symlink), dir.list_dir (out-param -> returned array), dir.current_dir, stat metadata (file_mode/uid/gid), readlink, console.readLine, and toml/msgpack/base64 decoders. Behavior-preserving (unwrap_or with prior sentinels, is_ok on writes). Import core.result as res / core.option as opt to avoid shadowing by local 'result' variables. Builds clean against Reef 0.7.6.
Author:
Chris Tusa <chris.tusa@leafscale.com>
Date:
Jul 17, 2026 19:04
Changeset:
88dbd80325ea9540043ae628a8a58a28d77f3081
Branch:
default
Changed files:
Diff
diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/build.reef --- a/src/commands/build.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/build.reef Fri Jul 17 19:04:08 2026 -0500 @@ -37,6 +37,7 @@ import util.mtree import util.http as uhttp import exitcodes as ec +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -129,7 +130,7 @@ // Handle "." for current directory if port_path == "." - port_path = dir.current_dir() + port_path = res.unwrap_or(dir.current_dir(), "") end if // Load configuration @@ -531,7 +532,7 @@ process.process_wait(pid) end if - let ts = file.readFile(tmp_file) + let ts = res.unwrap_or(file.readFile(tmp_file), "") // Cleanup let rm_cmd = "rm -f \"" + tmp_file + "\"" @@ -666,7 +667,7 @@ end if end if - if not dir.create_dir_all(ctx.work_dir) + if not res.is_ok(dir.create_dir_all(ctx.work_dir)) return false end if @@ -679,14 +680,14 @@ end if end if - if not dir.create_dir_all(ctx.pkg_dir) + if not res.is_ok(dir.create_dir_all(ctx.pkg_dir)) return false end if // Ensure sources directory exists let sources_dir = config.get_sources_dir(ctx.cfg) if not dir.dir_exists(sources_dir) - if not dir.create_dir_all(sources_dir) + if not res.is_ok(dir.create_dir_all(sources_dir)) return false end if end if @@ -694,7 +695,7 @@ // Ensure packages directory exists let packages_dir = config.get_packages_dir(ctx.cfg) if not dir.dir_exists(packages_dir) - if not dir.create_dir_all(packages_dir) + if not res.is_ok(dir.create_dir_all(packages_dir)) return false end if end if @@ -1111,7 +1112,7 @@ process.process_wait(pid) // Read result - let content = file.readFile(tmp_file) + let content = res.unwrap_or(file.readFile(tmp_file), "") // Clean up let rm_cmd = "rm -f \"" + tmp_file + "\"" @@ -1181,7 +1182,7 @@ end if end if - return file.writeFile(pkginfo_path, content) + return res.is_ok(file.writeFile(pkginfo_path, content)) end generate_pkginfo fn generate_manifest_file(ctx: BuildContext): bool @@ -1195,7 +1196,7 @@ return false end if - return file.writeFile(manifest_path, content) + return res.is_ok(file.writeFile(manifest_path, content)) end generate_manifest_file proc cleanup_build(ctx: BuildContext) diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/clean.reef --- a/src/commands/clean.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/clean.reef Fri Jul 17 19:04:08 2026 -0500 @@ -27,6 +27,7 @@ import types import util.color import exitcodes as ec +import core.result as res export fn execute(): int @@ -187,8 +188,8 @@ return 0 end if - mut entries: [string] = new [string](512) - let count = dir.list_dir(dir_path, entries, 512) + let entries = res.unwrap_or(dir.list_dir(dir_path), new [string](0)) + let count = entries.length() if str.length(extension) == 0 return count @@ -211,8 +212,8 @@ return 0 end if - mut entries: [string] = new [string](256) - let count = dir.list_dir(dir_path, entries, 256) + let entries = res.unwrap_or(dir.list_dir(dir_path), new [string](0)) + let count = entries.length() // Count only directories (packages being built) mut dirs = 0 diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/install.reef --- a/src/commands/install.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/install.reef Fri Jul 17 19:04:08 2026 -0500 @@ -42,6 +42,7 @@ import util.color import util.priv import exitcodes as ec +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -556,8 +557,8 @@ let packages_dir = config.get_packages_dir(cfg) // Find all matching packages and select highest version - mut entries: [string] = new [string](256) - let entry_count = dir.list_dir(packages_dir, entries, 256) + let entries = res.unwrap_or(dir.list_dir(packages_dir), new [string](0)) + let entry_count = entries.length() // Collect all matching package files mut best_file = "" @@ -712,7 +713,7 @@ end if end if - if not dir.create_dir_all(extract_dir) + if not res.is_ok(dir.create_dir_all(extract_dir)) return "" end if @@ -792,7 +793,7 @@ return 0 end if - let content = file.readFile(manifest_path) + let content = res.unwrap_or(file.readFile(manifest_path), "") if str.length(content) == 0 return 0 end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/key.reef --- a/src/commands/key.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/key.reef Fri Jul 17 19:04:08 2026 -0500 @@ -25,6 +25,7 @@ import core.signing import util.color import exitcodes as ec +import core.result as res export fn execute(): int @@ -175,7 +176,7 @@ color.print_action("Importing key: " + key_name) - let key_data = file.readFile(key_file) + let key_data = res.unwrap_or(file.readFile(key_file), "") let result = signing.import_key(key_data, key_name) if result.success @@ -197,7 +198,7 @@ color.print_action("Public key for " + name + ":") println("") - let key_data = file.readFile(pub_path) + let key_data = res.unwrap_or(file.readFile(pub_path), "") println(key_data) end export_key @@ -286,7 +287,7 @@ // Create keyring directory if not dir.dir_exists(keyring) - if not dir.create_dir_all(keyring) + if not res.is_ok(dir.create_dir_all(keyring)) color.print_error("Failed to create keyring directory: " + keyring) return end if @@ -297,7 +298,7 @@ // Create trusted-keys directory if not dir.dir_exists(trusted_keys_dir) - if not dir.create_dir_all(trusted_keys_dir) + if not res.is_ok(dir.create_dir_all(trusted_keys_dir)) color.print_error("Failed to create trusted-keys directory") return end if @@ -332,7 +333,7 @@ // Ensure trusted-keys directory exists if not dir.dir_exists(trusted_dir) - if not dir.create_dir_all(trusted_dir) + if not res.is_ok(dir.create_dir_all(trusted_dir)) color.print_error("Failed to create trusted-keys directory") return end if @@ -408,8 +409,8 @@ return end if - mut entries: [string] = new [string](64) - let count = dir.list_dir(trusted_dir, entries, 64) + let entries = res.unwrap_or(dir.list_dir(trusted_dir), new [string](0)) + let count = entries.length() if count == 0 color.print_info("No trusted keys") diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/ports.reef --- a/src/commands/ports.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/ports.reef Fri Jul 17 19:04:08 2026 -0500 @@ -27,6 +27,7 @@ import types import util.color import exitcodes as ec +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -96,7 +97,7 @@ return ec.EXIT_PKG_ALREADY_INSTALLED() end if - if not dir.create_dir_all(port_dir) + if not res.is_ok(dir.create_dir_all(port_dir)) color.print_error("Failed to create directory: " + port_dir) return ec.EXIT_PERMISSION_DENIED() end if @@ -105,7 +106,7 @@ let toml_path = path.join_path(port_dir, "package.toml") let toml_content = "[package]\nname = \"" + name + "\"\nversion = \"0.1.0\"\nrelease = 1\ndescription = \"\"\nurl = \"\"\nlicense = \"\"\nmaintainer = \"\"\narch = \"x86_64\"\n\n[dependencies]\nruntime = []\nbuild = []\n\n[[source]]\nfile = \"\"\nurls = []\nchecksum = \"SKIP\"\n\n[build]\nparallel = true\njobs = 0\n" - if not file.writeFile(toml_path, toml_content) + if not res.is_ok(file.writeFile(toml_path, toml_content)) color.print_error("Failed to write package.toml") return ec.EXIT_PERMISSION_DENIED() end if @@ -115,7 +116,7 @@ let dollar = "$" let build_content = "#!/bin/sh\n# Build script for " + name + "\nset -e\n\n# cd " + name + "-" + dollar + "{VERSION}\n\nMAKE=gmake\nif [ \"" + dollar + "(uname -s)\" != \"SunOS\" ]; then\n MAKE=make\nfi\n\n# ./configure --prefix=/usr\n# " + dollar + "MAKE " + dollar + "{MAKEFLAGS}\n# " + dollar + "MAKE DESTDIR=\"" + dollar + "{DESTDIR}\" install\n" - if not file.writeFile(build_path, build_content) + if not res.is_ok(file.writeFile(build_path, build_content)) color.print_error("Failed to write build.sh") return ec.EXIT_PERMISSION_DENIED() end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/remove.reef --- a/src/commands/remove.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/remove.reef Fri Jul 17 19:04:08 2026 -0500 @@ -37,6 +37,7 @@ import fs.ops import util.priv import exitcodes as ec +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -237,7 +238,7 @@ mut manifest_count = 0 let manifest_path = database.get_manifest_path(pkg_name) if file.fileExists(manifest_path) - let manifest_content = file.readFile(manifest_path) + let manifest_content = res.unwrap_or(file.readFile(manifest_path), "") if str.length(manifest_content) > 0 manifest_count = mtree.parse_manifest(manifest_content, manifest_entries, 8192) end if @@ -332,7 +333,7 @@ end if end if - if not ops.remove_file(full_path) + if not res.is_ok(ops.remove_file(full_path)) color.print_warning("Failed to remove: " + full_path) all_success = false end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/repo.reef --- a/src/commands/repo.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/repo.reef Fri Jul 17 19:04:08 2026 -0500 @@ -25,6 +25,7 @@ import core.repository import util.color import exitcodes as ec +import core.result as res export fn execute(): int @@ -199,7 +200,7 @@ // Ensure directory exists if not dir.dir_exists(repos_dir) - if not dir.create_dir_all(repos_dir) + if not res.is_ok(dir.create_dir_all(repos_dir)) color.print_error("Failed to create repos directory") return end if @@ -213,7 +214,7 @@ content = content + "enabled = true\n" content = content + "signed = false\n" - if not file.writeFile(repo_path, content) + if not res.is_ok(file.writeFile(repo_path, content)) color.print_error("Failed to write repository file") return end if @@ -250,7 +251,7 @@ end if // Read current content - let content = file.readFile(repo_path) + let content = res.unwrap_or(file.readFile(repo_path), "") // Replace enabled line mut new_content = "" @@ -260,7 +261,7 @@ new_content = str.replace(content, "enabled = true", "enabled = false") end if - if not file.writeFile(repo_path, new_content) + if not res.is_ok(file.writeFile(repo_path, new_content)) color.print_error("Failed to update repository file") return end if @@ -302,7 +303,7 @@ // Create the repository directory if not dir.dir_exists(repo_path) - if not dir.create_dir_all(repo_path) + if not res.is_ok(dir.create_dir_all(repo_path)) color.print_error("Failed to create repository directory") return end if @@ -311,7 +312,7 @@ // Create packages subdirectory let packages_dir = repo_path + "/packages" if not dir.dir_exists(packages_dir) - if not dir.create_dir_all(packages_dir) + if not res.is_ok(dir.create_dir_all(packages_dir)) color.print_error("Failed to create packages directory") return end if @@ -334,7 +335,7 @@ content = content + "# Packages will be listed below by coral repo rebuild\n" content = content + "[packages]\n" - if not file.writeFile(manifest_path, content) + if not res.is_ok(file.writeFile(manifest_path, content)) color.print_error("Failed to write repo.toml") return end if @@ -356,8 +357,8 @@ end if // Scan for package files - mut entries: [string] = new [string](1024) - let entry_count = dir.list_dir(packages_dir, entries, 1024) + let entries = res.unwrap_or(dir.list_dir(packages_dir), new [string](0)) + let entry_count = entries.length() mut pkg_count = 0 mut packages_content = "" @@ -392,7 +393,7 @@ content = content + "[packages]\n" content = content + packages_content - if not file.writeFile(manifest_path, content) + if not res.is_ok(file.writeFile(manifest_path, content)) color.print_error("Failed to write repo.toml") return end if @@ -473,7 +474,7 @@ end if // Update repo.toml to indicate it's signed - let content = file.readFile(manifest_path) + let content = res.unwrap_or(file.readFile(manifest_path), "") let new_content = str.replace(content, "signed = false", "signed = true") file.writeFile(manifest_path, new_content) @@ -506,8 +507,8 @@ end if // List all public keys and try each - mut entries: [string] = new [string](64) - let count = dir.list_dir(keyring, entries, 64) + let entries = res.unwrap_or(dir.list_dir(keyring), new [string](0)) + let count = entries.length() mut i = 0 mut verified = false diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/sync.reef --- a/src/commands/sync.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/sync.reef Fri Jul 17 19:04:08 2026 -0500 @@ -28,6 +28,7 @@ import core.portindex import util.color import exitcodes as ec +import core.result as res export fn execute(): int @@ -98,8 +99,8 @@ let cat_path = path.join_path(ports_dir, cat) if dir.dir_exists(cat_path) - mut entries: [string] = new [string](256) - let count = dir.list_dir(cat_path, entries, 256) + let entries = res.unwrap_or(dir.list_dir(cat_path), new [string](0)) + let count = entries.length() // Count valid ports (directories with package.toml) mut port_count = 0 diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/upgrade.reef --- a/src/commands/upgrade.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/upgrade.reef Fri Jul 17 19:04:08 2026 -0500 @@ -32,6 +32,7 @@ import util.color import util.version as ver import exitcodes as ec +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -419,7 +420,7 @@ end if end if - if not dir.create_dir_all(extract_dir) + if not res.is_ok(dir.create_dir_all(extract_dir)) return "" end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/commands/verify.reef --- a/src/commands/verify.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/commands/verify.reef Fri Jul 17 19:04:08 2026 -0500 @@ -31,6 +31,7 @@ import exitcodes as ec import fs.stat import fs.link +import core.result as res export fn execute(opts: types.GlobalOptions): int @@ -70,7 +71,7 @@ return ec.EXIT_PKG_INVALID() end if - let manifest_content = file.readFile(manifest_path) + let manifest_content = res.unwrap_or(file.readFile(manifest_path), "") if str.length(manifest_content) == 0 color.print_error("Empty manifest for " + pkg_name) return ec.EXIT_PKG_INVALID() @@ -114,7 +115,7 @@ else // Check mode let expected_mode = mtree.entry_mode(entry) - let actual_mode = stat.file_mode(full_path) + let actual_mode = res.unwrap_or(stat.file_mode(full_path), 0) // Compare lower 12 bits (permissions + setuid/setgid/sticky) if (actual_mode % 4096) != (expected_mode % 4096) if opts.verbose @@ -148,7 +149,7 @@ // Check mode let expected_mode = mtree.entry_mode(entry) - let actual_mode = stat.file_mode(full_path) + let actual_mode = res.unwrap_or(stat.file_mode(full_path), 0) if (actual_mode % 4096) != (expected_mode % 4096) if opts.verbose color.print_warning("MODE " + rel_path + " (expected " + int_to_octal(expected_mode) + ", got " + int_to_octal(actual_mode) + ")") @@ -162,8 +163,8 @@ // Check ownership let expected_uid = mtree.name_to_uid(mtree.entry_uname(entry)) let expected_gid = mtree.name_to_gid(mtree.entry_gname(entry)) - let actual_uid = stat.file_uid(full_path) - let actual_gid = stat.file_gid(full_path) + let actual_uid = res.unwrap_or(stat.file_uid(full_path), 0) + let actual_gid = res.unwrap_or(stat.file_gid(full_path), 0) if actual_uid != expected_uid or actual_gid != expected_gid if opts.verbose color.print_warning("OWNER " + rel_path + " (expected " + mtree.entry_uname(entry) + ":" + mtree.entry_gname(entry) + ")") @@ -190,7 +191,7 @@ end if else let expected_target = mtree.entry_link(entry) - let actual_target = link.readlink(full_path) + let actual_target = res.unwrap_or(link.readlink(full_path), "") if not str.equals(actual_target, expected_target) if opts.verbose color.print_warning("LINK " + rel_path + " -> " + actual_target + " (expected " + expected_target + ")") diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/config.reef --- a/src/core/config.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/config.reef Fri Jul 17 19:04:08 2026 -0500 @@ -21,6 +21,7 @@ import io.file import core.str import encoding.toml +import core.result as res export // Configuration structure @@ -210,7 +211,7 @@ end if // Read config file - let content = file.readFile(types.get_config_file()) + let content = res.unwrap_or(file.readFile(types.get_config_file()), "") if str.length(content) == 0 return cfg end if @@ -218,7 +219,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return cfg diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/database.reef --- a/src/core/database.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/database.reef Fri Jul 17 19:04:08 2026 -0500 @@ -25,6 +25,7 @@ import encoding.toml import util.mtree import sys.process +import core.result as res export // Check if a package is installed @@ -105,7 +106,7 @@ // Initialize the database directory structure fn init_db(): bool if not dir.dir_exists(types.get_db_dir()) - return dir.create_dir_all(types.get_db_dir()) + return res.is_ok(dir.create_dir_all(types.get_db_dir())) end if return true end init_db @@ -126,8 +127,8 @@ return 0 end if - mut entries: [string] = new [string](256) - let entry_count = dir.list_dir(types.get_db_dir(), entries, 256) + let entries = res.unwrap_or(dir.list_dir(types.get_db_dir()), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 @@ -161,7 +162,7 @@ // Read pkg.toml let toml_path = pkg_toml_path(name) - let content = file.readFile(toml_path) + let content = res.unwrap_or(file.readFile(toml_path), "") if str.length(content) == 0 return new_installed_package() end if @@ -169,7 +170,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return new_installed_package() @@ -193,7 +194,7 @@ // Read files list let files_path = pkg_files_path(name) if file.fileExists(files_path) - let files_content = file.readFile(files_path) + let files_content = res.unwrap_or(file.readFile(files_path), "") if str.length(files_content) > 0 let alloc_size = count_newlines(files_content) + 16 mut files_arr: [string] = new [string](alloc_size) @@ -270,7 +271,7 @@ // Create package directory let pkg_dir = pkg_db_dir(pkg.info.name) if not dir.dir_exists(pkg_dir) - if not dir.create_dir_all(pkg_dir) + if not res.is_ok(dir.create_dir_all(pkg_dir)) return false end if end if @@ -278,7 +279,7 @@ // Write pkg.toml let toml_content = generate_pkg_toml(pkg) let toml_path = pkg_toml_path(pkg.info.name) - if not file.writeFile(toml_path, toml_content) + if not res.is_ok(file.writeFile(toml_path, toml_content)) return false end if @@ -401,12 +402,12 @@ if file.fileExists(manifest_path) // Store the full manifest for future use (verify, manifest-based remove) let manifest_store = path.join_path(pkg_db_dir(pkg.info.name), "manifest.mtree") - let manifest_content = file.readFile(manifest_path) + let manifest_content = res.unwrap_or(file.readFile(manifest_path), "") file.writeFile(manifest_store, manifest_content) // Also generate files.txt for backward compatibility let result = extract_paths_from_manifest(manifest_content) - return file.writeFile(files_path, result) + return res.is_ok(file.writeFile(files_path, result)) end if // Legacy: .FOOTPRINT @@ -416,14 +417,14 @@ return true end if - let content = file.readFile(footprint_path) + let content = res.unwrap_or(file.readFile(footprint_path), "") if str.length(content) == 0 file.writeFile(files_path, "") return true end if let result = process_footprint(content) - return file.writeFile(files_path, result) + return res.is_ok(file.writeFile(files_path, result)) end register_from_extract_dir // Helper to remove a file @@ -484,7 +485,7 @@ end if // Remove the package directory - return dir.remove_dir(pkg_dir) + return res.is_ok(dir.remove_dir(pkg_dir)) end unregister_package // Get list of files owned by a package @@ -498,7 +499,7 @@ return 0 end if - let content = file.readFile(files_path) + let content = res.unwrap_or(file.readFile(files_path), "") if str.length(content) == 0 return 0 end if @@ -573,11 +574,11 @@ // Note: We'd need to parse the alternatives array from pkg.toml // For now, check if this package provides the alternative let toml_path = pkg_toml_path(pkg_name) - let content = file.readFile(toml_path) + let content = res.unwrap_or(file.readFile(toml_path), "") if str.length(content) > 0 let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if toml.toml_has_key(keys, vals, entry_count, "package.alternatives") let alts_val = toml.toml_get(keys, vals, entry_count, "package.alternatives") @@ -618,7 +619,7 @@ // Create scripts directory in database if not dir.dir_exists(dest_scripts) - if not dir.create_dir_all(dest_scripts) + if not res.is_ok(dir.create_dir_all(dest_scripts)) return false end if end if @@ -651,9 +652,9 @@ let dest_config = pkg_config_path(name) // Copy the config files list - let content = file.readFile(src_config) + let content = res.unwrap_or(file.readFile(src_config), "") if str.length(content) > 0 - return file.writeFile(dest_config, content) + return res.is_ok(file.writeFile(dest_config, content)) end if return true @@ -666,7 +667,7 @@ return 0 end if - let content = file.readFile(config_path) + let content = res.unwrap_or(file.readFile(config_path), "") if str.length(content) == 0 return 0 end if @@ -721,7 +722,7 @@ fn init_db_rooted(root: string): bool let db_dir = get_db_dir_rooted(root) if not dir.dir_exists(db_dir) - return dir.create_dir_all(db_dir) + return res.is_ok(dir.create_dir_all(db_dir)) end if return true end init_db_rooted @@ -745,7 +746,7 @@ // Create package directory let pkg_dir = pkg_db_dir_rooted(pkg.info.name, root) if not dir.dir_exists(pkg_dir) - if not dir.create_dir_all(pkg_dir) + if not res.is_ok(dir.create_dir_all(pkg_dir)) return false end if end if @@ -753,7 +754,7 @@ // Write pkg.toml let toml_content = generate_pkg_toml(pkg) let toml_path = pkg_toml_path_rooted(pkg.info.name, root) - if not file.writeFile(toml_path, toml_content) + if not res.is_ok(file.writeFile(toml_path, toml_content)) return false end if @@ -774,12 +775,12 @@ if file.fileExists(manifest_path) // Store the full manifest let manifest_store = path.join_path(pkg_db_dir_rooted(pkg.info.name, root), "manifest.mtree") - let manifest_content = file.readFile(manifest_path) + let manifest_content = res.unwrap_or(file.readFile(manifest_path), "") file.writeFile(manifest_store, manifest_content) // Also generate files.txt for backward compatibility let result = extract_paths_from_manifest(manifest_content) - return file.writeFile(files_path, result) + return res.is_ok(file.writeFile(files_path, result)) end if // Legacy: .FOOTPRINT @@ -789,14 +790,14 @@ return true end if - let content = file.readFile(footprint_path) + let content = res.unwrap_or(file.readFile(footprint_path), "") if str.length(content) == 0 file.writeFile(files_path, "") return true end if let result = process_footprint(content) - return file.writeFile(files_path, result) + return res.is_ok(file.writeFile(files_path, result)) end register_from_extract_dir_rooted // Get scripts directory with alternate root @@ -815,7 +816,7 @@ let dest_scripts = get_scripts_dir_rooted(name, root) if not dir.dir_exists(dest_scripts) - if not dir.create_dir_all(dest_scripts) + if not res.is_ok(dir.create_dir_all(dest_scripts)) return false end if end if @@ -844,9 +845,9 @@ let dest_config = pkg_config_path_rooted(name, root) - let content = file.readFile(src_config) + let content = res.unwrap_or(file.readFile(src_config), "") if str.length(content) > 0 - return file.writeFile(dest_config, content) + return res.is_ok(file.writeFile(dest_config, content)) end if return true @@ -859,8 +860,8 @@ return 0 end if - mut entries: [string] = new [string](256) - let entry_count = dir.list_dir(db_dir, entries, 256) + let entries = res.unwrap_or(dir.list_dir(db_dir), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 @@ -889,7 +890,7 @@ // Read pkg.toml let toml_path = pkg_toml_path_rooted(name, root) - let content = file.readFile(toml_path) + let content = res.unwrap_or(file.readFile(toml_path), "") if str.length(content) == 0 return new_installed_package() end if @@ -897,7 +898,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return new_installed_package() @@ -921,7 +922,7 @@ // Read files list let files_path = pkg_files_path_rooted(name, root) if file.fileExists(files_path) - let files_content = file.readFile(files_path) + let files_content = res.unwrap_or(file.readFile(files_path), "") if str.length(files_content) > 0 let alloc_size = count_newlines(files_content) + 16 mut files_arr: [string] = new [string](alloc_size) @@ -954,7 +955,7 @@ return 0 end if - let content = file.readFile(files_path) + let content = res.unwrap_or(file.readFile(files_path), "") if str.length(content) == 0 return 0 end if @@ -1055,7 +1056,7 @@ end if // Remove the package directory - return dir.remove_dir(pkg_dir) + return res.is_ok(dir.remove_dir(pkg_dir)) end unregister_package_rooted end module diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/groups.reef --- a/src/core/groups.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/groups.reef Fri Jul 17 19:04:08 2026 -0500 @@ -23,6 +23,7 @@ import io.path import encoding.toml import types +import core.result as res export type GroupResult @@ -83,7 +84,7 @@ return error_result("Group not found: " + group_name) end if - let content = file.readFile(group_file) + let content = res.unwrap_or(file.readFile(group_file), "") if str.length(content) == 0 return error_result("Failed to read group file") end if @@ -91,7 +92,7 @@ // Parse TOML using key/value arrays let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return error_result("Invalid group file format") @@ -122,8 +123,8 @@ return 0 end if - mut entries: [string] = new [string](64) - let entry_count = dir.list_dir(groups_dir, entries, 64) + let entries = res.unwrap_or(dir.list_dir(groups_dir), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/package.reef --- a/src/core/package.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/package.reef Fri Jul 17 19:04:08 2026 -0500 @@ -31,6 +31,7 @@ import fs.perm import fs.link import fs.ops +import core.result as res export // Package extraction result @@ -119,7 +120,7 @@ // Ensure destination directory exists if not dir.dir_exists(dest_dir) - if not dir.create_dir_all(dest_dir) + if not res.is_ok(dir.create_dir_all(dest_dir)) return extract_error("Failed to create extraction directory: " + dest_dir) end if end if @@ -147,7 +148,7 @@ return info end if - let content = file.readFile(pkginfo_path) + let content = res.unwrap_or(file.readFile(pkginfo_path), "") if str.length(content) == 0 return info end if @@ -155,7 +156,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return info @@ -191,7 +192,7 @@ // Try .MANIFEST first (v2 format) let manifest_path = path.join_path(pkg_dir, ".MANIFEST") if file.fileExists(manifest_path) - let content = file.readFile(manifest_path) + let content = res.unwrap_or(file.readFile(manifest_path), "") if str.length(content) > 0 mut entries: [mtree.ManifestEntry] = new [mtree.ManifestEntry](max_count) let entry_count = mtree.parse_manifest(content, entries, max_count) @@ -223,7 +224,7 @@ return 0 end if - let content = file.readFile(footprint_path) + let content = res.unwrap_or(file.readFile(footprint_path), "") if str.length(content) == 0 return 0 end if @@ -276,7 +277,7 @@ return 0 end if - let content = file.readFile(manifest_path) + let content = res.unwrap_or(file.readFile(manifest_path), "") if str.length(content) == 0 return 0 end if @@ -320,7 +321,7 @@ if str.equals(etype, "dir") // Create directory if it doesn't exist if not dir.dir_exists(dest_path) - if not dir.create_dir_all(dest_path) + if not res.is_ok(dir.create_dir_all(dest_path)) return false end if end if @@ -348,7 +349,7 @@ end if // Copy file preserving permissions from source - if not ops.copy_file_preserve(src_path, dest_path) + if not res.is_ok(ops.copy_file_preserve(src_path, dest_path)) return false end if @@ -381,7 +382,7 @@ end if // Create symlink - if not link.symlink(link_target, dest_path) + if not res.is_ok(link.symlink(link_target, dest_path)) return false end if end if @@ -445,7 +446,7 @@ if str.equals(etype, "file") or str.equals(etype, "link") if stat.is_symlink(full_path) or stat.exists(full_path) - if not ops.remove_file(full_path) + if not res.is_ok(ops.remove_file(full_path)) all_success = false end if end if @@ -809,7 +810,7 @@ return 0 end if - let content = file.readFile(config_path) + let content = res.unwrap_or(file.readFile(config_path), "") if str.length(content) == 0 return 0 end if @@ -862,7 +863,7 @@ dir.create_dir_all(dest_dir) end if - return ops.copy_file_preserve(src_path, dest_path) + return res.is_ok(ops.copy_file_preserve(src_path, dest_path)) end if // File exists — check if user has modified it @@ -870,18 +871,18 @@ // No stored checksum (fresh install over existing file or legacy package) // Be safe: install as .pkg-new, preserve user's file let new_path = dest_path + ".pkg-new" - return ops.copy_file_preserve(src_path, new_path) + return res.is_ok(ops.copy_file_preserve(src_path, new_path)) end if let installed_sha = checksum.sha256_file(dest_path) if str.equals(installed_sha, stored_sha256) // User has not modified the config — safe to overwrite - return ops.copy_file_preserve(src_path, dest_path) + return res.is_ok(ops.copy_file_preserve(src_path, dest_path)) else // User has modified the config — preserve their version let new_path = dest_path + ".pkg-new" - return ops.copy_file_preserve(src_path, new_path) + return res.is_ok(ops.copy_file_preserve(src_path, new_path)) end if end install_config_file @@ -933,7 +934,7 @@ if str.equals(etype, "dir") if not dir.dir_exists(dest_path) - if not dir.create_dir_all(dest_path) + if not res.is_ok(dir.create_dir_all(dest_path)) return false end if end if @@ -958,7 +959,7 @@ ops.remove_file(dest_path) end if - if not ops.copy_file_preserve(src_path, dest_path) + if not res.is_ok(ops.copy_file_preserve(src_path, dest_path)) return false end if @@ -986,7 +987,7 @@ dir.create_dir_all(parent) end if - if not link.symlink(link_target, dest_path) + if not res.is_ok(link.symlink(link_target, dest_path)) return false end if end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/pkgdb.reef --- a/src/core/pkgdb.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/pkgdb.reef Fri Jul 17 19:04:08 2026 -0500 @@ -35,6 +35,7 @@ import core.database import encoding.msgpack import encoding.base64 +import core.result as res export // Package index entry (for packages.db) @@ -267,7 +268,7 @@ end if // Read base64-encoded content - let encoded = file.readFile(db_path) + let encoded = res.unwrap_or(file.readFile(db_path), "") if str.length(encoded) == 0 return index end if @@ -275,7 +276,7 @@ // Decode base64 to buffer let buf_size = str.length(encoded) // Decoded will be smaller mut buf: [int] = new [int](buf_size) - let buf_len = base64.base64_decode_bytes(encoded, buf, buf_size) + let buf_len = res.unwrap_or(base64.base64_decode_bytes(encoded, buf, buf_size), 0) if buf_len == 0 return index @@ -289,34 +290,34 @@ return index end if - let map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) // Iterate through map entries mut entry_idx = 0 while entry_idx < map_len and offset < buf_len // Get key - let key = msgpack.msgpack_unpack_string(buf, offset) + let key = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) if str.equals(key, "version") - index.version = msgpack.msgpack_unpack_int(buf, offset) + index.version = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "generated") - index.generated = msgpack.msgpack_unpack_string(buf, offset) + index.generated = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "package_count") - index.package_count = msgpack.msgpack_unpack_int(buf, offset) + index.package_count = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "packages") // Parse packages array - let arr_len = msgpack.msgpack_unpack_array_len(buf, offset) + let arr_len = res.unwrap_or(msgpack.msgpack_unpack_array_len(buf, offset), 0) offset = offset + array_header_size(buf, offset) mut pkg_idx = 0 while pkg_idx < arr_len and pkg_idx < MAX_PACKAGES and offset < buf_len // Each package is a map - let pkg_map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let pkg_map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) mut entry = empty_pkg_entry() @@ -324,21 +325,21 @@ mut pkg_field = 0 while pkg_field < pkg_map_len and offset < buf_len - let field_key = msgpack.msgpack_unpack_string(buf, offset) + let field_key = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) if str.equals(field_key, "name") - entry.name = msgpack.msgpack_unpack_string(buf, offset) + entry.name = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") elif str.equals(field_key, "version") - entry.version = msgpack.msgpack_unpack_string(buf, offset) + entry.version = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") elif str.equals(field_key, "release") - entry.release = msgpack.msgpack_unpack_int(buf, offset) + entry.release = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) elif str.equals(field_key, "description") - entry.description = msgpack.msgpack_unpack_string(buf, offset) + entry.description = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") elif str.equals(field_key, "installed_date") - entry.installed_date = msgpack.msgpack_unpack_string(buf, offset) + entry.installed_date = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") elif str.equals(field_key, "file_count") - entry.file_count = msgpack.msgpack_unpack_int(buf, offset) + entry.file_count = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) end if offset = offset + msgpack.msgpack_value_size(buf, offset) @@ -371,7 +372,7 @@ end if // Read base64-encoded content - let encoded = file.readFile(db_path) + let encoded = res.unwrap_or(file.readFile(db_path), "") let encoded_len = str.length(encoded) if encoded_len == 0 return index @@ -380,7 +381,7 @@ // Decode base64 to buffer let buf_size = encoded_len // Decoded will be smaller mut buf: [int] = new [int](buf_size) - let buf_len = base64.base64_decode_bytes(encoded, buf, buf_size) + let buf_len = res.unwrap_or(base64.base64_decode_bytes(encoded, buf, buf_size), 0) if buf_len <= 0 return index @@ -394,37 +395,37 @@ return index end if - let map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) // Iterate through map entries mut entry_idx = 0 while entry_idx < map_len and offset < buf_len // Get key - let key = msgpack.msgpack_unpack_string(buf, offset) + let key = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) if str.equals(key, "version") - index.version = msgpack.msgpack_unpack_int(buf, offset) + index.version = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "generated") - index.generated = msgpack.msgpack_unpack_string(buf, offset) + index.generated = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "file_count") - index.file_count = msgpack.msgpack_unpack_int(buf, offset) + index.file_count = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "files") // Parse files map - let files_map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let files_map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) mut file_idx = 0 while file_idx < files_map_len and file_idx < MAX_FILES and offset < buf_len // Key is file path, value is owner - let file_path = msgpack.msgpack_unpack_string(buf, offset) + let file_path = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) - let owner = msgpack.msgpack_unpack_string(buf, offset) + let owner = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) index.file_paths[file_idx] = file_path @@ -504,7 +505,7 @@ fn init_db(): bool let db = db_dir() if not dir.dir_exists(db) - return dir.create_dir_all(db) + return res.is_ok(dir.create_dir_all(db)) end if return true end init_db @@ -937,7 +938,7 @@ fn init_db_rooted(root: string): bool let db = db_dir_rooted(root) if not dir.dir_exists(db) - return dir.create_dir_all(db) + return res.is_ok(dir.create_dir_all(db)) end if return true end init_db_rooted @@ -959,7 +960,7 @@ if pkg_len > 0 // Encode to base64 and write let pkg_encoded = base64.base64_encode_bytes(pkg_buf, pkg_len) - if not file.writeFile(packages_db_path_rooted(root), pkg_encoded) + if not res.is_ok(file.writeFile(packages_db_path_rooted(root), pkg_encoded)) return false end if end if @@ -974,7 +975,7 @@ if files_len > 0 // Encode to base64 and write let files_encoded = base64.base64_encode_bytes(files_buf, files_len) - if not file.writeFile(files_db_path_rooted(root), files_encoded) + if not res.is_ok(file.writeFile(files_db_path_rooted(root), files_encoded)) return false end if end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/port.reef --- a/src/core/port.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/port.reef Fri Jul 17 19:04:08 2026 -0500 @@ -24,6 +24,7 @@ import core.str import core.config import encoding.toml +import core.result as res export // Load a port from a directory path, returns PortResult @@ -62,8 +63,8 @@ let groups_dir = types.get_groups_dir() let skip_groups = get_relative_top_dir(ports_dir, groups_dir) - mut entries: [string] = new [string](256) - let entry_count = dir.list_dir(ports_dir, entries, 256) + let entries = res.unwrap_or(dir.list_dir(ports_dir), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 @@ -377,7 +378,7 @@ end if // Read the TOML file - let content = file.readFile(toml_path) + let content = res.unwrap_or(file.readFile(toml_path), "") if str.length(content) == 0 return error_result("Failed to read package.toml or file is empty") end if @@ -385,7 +386,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return error_result("Failed to parse package.toml") @@ -562,8 +563,8 @@ return 0 end if - mut entries: [string] = new [string](256) - let entry_count = dir.list_dir(cat_path, entries, 256) + let entries = res.unwrap_or(dir.list_dir(cat_path), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/portindex.reef --- a/src/core/portindex.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/portindex.reef Fri Jul 17 19:04:08 2026 -0500 @@ -35,6 +35,7 @@ import core.config import encoding.msgpack import encoding.base64 +import core.result as res export type PortIndexEntry @@ -250,7 +251,7 @@ // Encode to base64 and write let encoded = base64.base64_encode_bytes(buf, buf_len) - return file.writeFile(ports_db_path(), encoded) + return res.is_ok(file.writeFile(ports_db_path(), encoded)) end rebuild_port_index // Build a port path from category and name @@ -345,14 +346,14 @@ return index end if - let encoded = file.readFile(db_path) + let encoded = res.unwrap_or(file.readFile(db_path), "") if str.length(encoded) == 0 return index end if let buf_size = str.length(encoded) mut buf: [int] = new [int](buf_size) - let buf_len = base64.base64_decode_bytes(encoded, buf, buf_size) + let buf_len = res.unwrap_or(base64.base64_decode_bytes(encoded, buf, buf_size), 0) if buf_len == 0 return index @@ -365,31 +366,31 @@ return index end if - let map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) mut entry_idx = 0 while entry_idx < map_len and offset < buf_len - let key = msgpack.msgpack_unpack_string(buf, offset) + let key = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) if str.equals(key, "version") - index.version = msgpack.msgpack_unpack_int(buf, offset) + index.version = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "generated") - index.generated = msgpack.msgpack_unpack_string(buf, offset) + index.generated = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "port_count") - index.port_count = msgpack.msgpack_unpack_int(buf, offset) + index.port_count = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(key, "ports") // Parse ports array - let arr_len = msgpack.msgpack_unpack_array_len(buf, offset) + let arr_len = res.unwrap_or(msgpack.msgpack_unpack_array_len(buf, offset), 0) offset = offset + array_header_size(buf, offset) mut port_idx = 0 while port_idx < arr_len and port_idx < MAX_PORTS and offset < buf_len - let port_map_len = msgpack.msgpack_unpack_map_len(buf, offset) + let port_map_len = res.unwrap_or(msgpack.msgpack_unpack_map_len(buf, offset), 0) offset = offset + map_header_size(buf, offset) mut entry = empty_port_entry() @@ -397,35 +398,35 @@ mut port_field = 0 while port_field < port_map_len and offset < buf_len - let field_key = msgpack.msgpack_unpack_string(buf, offset) + let field_key = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) if str.equals(field_key, "name") - entry.name = msgpack.msgpack_unpack_string(buf, offset) + entry.name = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "category") - entry.category = msgpack.msgpack_unpack_string(buf, offset) + entry.category = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "version") - entry.version = msgpack.msgpack_unpack_string(buf, offset) + entry.version = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "release") - entry.release = msgpack.msgpack_unpack_int(buf, offset) + entry.release = res.unwrap_or(msgpack.msgpack_unpack_int(buf, offset), 0) offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "description") - entry.description = msgpack.msgpack_unpack_string(buf, offset) + entry.description = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "port_dir") - entry.port_dir = msgpack.msgpack_unpack_string(buf, offset) + entry.port_dir = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) elif str.equals(field_key, "runtime_deps") // Parse deps array - let deps_len = msgpack.msgpack_unpack_array_len(buf, offset) + let deps_len = res.unwrap_or(msgpack.msgpack_unpack_array_len(buf, offset), 0) offset = offset + array_header_size(buf, offset) mut dep_idx = 0 while dep_idx < deps_len and dep_idx < 64 and offset < buf_len - entry.runtime_deps[dep_idx] = msgpack.msgpack_unpack_string(buf, offset) + entry.runtime_deps[dep_idx] = res.unwrap_or(msgpack.msgpack_unpack_string(buf, offset), "") offset = offset + msgpack.msgpack_value_size(buf, offset) dep_idx = dep_idx + 1 end while diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/repository.reef --- a/src/core/repository.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/repository.reef Fri Jul 17 19:04:08 2026 -0500 @@ -25,6 +25,7 @@ import util.http as uhttp import util.color import types +import core.result as res export type Repository @@ -132,7 +133,7 @@ return error_result("Repository file not found: " + repo_path) end if - let content = file.readFile(repo_path) + let content = res.unwrap_or(file.readFile(repo_path), "") if str.length(content) == 0 return error_result("Empty repository file: " + repo_path) end if @@ -140,7 +141,7 @@ // Parse TOML let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return error_result("Failed to parse repository file: " + repo_path) @@ -179,8 +180,8 @@ return 0 end if - mut entries: [string] = new [string](64) - let entry_count = dir.list_dir(repos_dir, entries, 64) + let entries = res.unwrap_or(dir.list_dir(repos_dir), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 @@ -229,7 +230,7 @@ // Ensure cache directory exists let cache_dir = "/var/lib/coral/repos" if not dir.dir_exists(cache_dir) - if not dir.create_dir_all(cache_dir) + if not res.is_ok(dir.create_dir_all(cache_dir)) return false end if end if @@ -284,7 +285,7 @@ end if // Read cached manifest - let content = file.readFile(cache_path) + let content = res.unwrap_or(file.readFile(cache_path), "") if str.length(content) == 0 return pkg_error_result("Empty repository manifest") end if @@ -292,7 +293,7 @@ // Parse TOML to find the package let keys = toml.toml_alloc_keys() let vals = toml.toml_alloc_values() - let entry_count = toml.toml_parse(content, keys, vals) + let entry_count = res.unwrap_or(toml.toml_parse(content, keys, vals), 0) if entry_count == 0 return pkg_error_result("Failed to parse repository manifest") @@ -358,7 +359,7 @@ // Ensure packages cache directory exists let cache_dir = types.get_packages_dir() if not dir.dir_exists(cache_dir) - if not dir.create_dir_all(cache_dir) + if not res.is_ok(dir.create_dir_all(cache_dir)) color.print_error("Failed to create packages cache directory") return "" end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/core/signing.reef --- a/src/core/signing.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/core/signing.reef Fri Jul 17 19:04:08 2026 -0500 @@ -22,6 +22,7 @@ import io.dir import io.path import sys.process +import core.result as res export type KeyPair @@ -93,7 +94,7 @@ // Ensure keyring directory exists if not dir.dir_exists(keyring) - if not dir.create_dir_all(keyring) + if not res.is_ok(dir.create_dir_all(keyring)) return error_sign_result("Failed to create keyring directory") end if end if @@ -187,7 +188,7 @@ let keyring = get_keyring_dir() if not dir.dir_exists(keyring) - if not dir.create_dir_all(keyring) + if not res.is_ok(dir.create_dir_all(keyring)) return error_sign_result("Failed to create keyring directory") end if end if @@ -198,7 +199,7 @@ return error_sign_result("Key already exists: " + name) end if - if not file.writeFile(key_path, key_data) + if not res.is_ok(file.writeFile(key_path, key_data)) return error_sign_result("Failed to write key file") end if @@ -213,8 +214,8 @@ return 0 end if - mut entries: [string] = new [string](64) - let entry_count = dir.list_dir(keyring, entries, 64) + let entries = res.unwrap_or(dir.list_dir(keyring), new [string](0)) + let entry_count = entries.length() mut count = 0 mut i = 0 @@ -232,7 +233,7 @@ // Read public key let pub_path = path.join_path(keyring, entry) - kp.public_key = file.readFile(pub_path) + kp.public_key = res.unwrap_or(file.readFile(pub_path), "") // Check for private key let priv_path = path.join_path(keyring, name + ".key") @@ -312,8 +313,8 @@ // Get keys from trusted-keys directory if dir.dir_exists(trusted_dir) - mut entries: [string] = new [string](32) - let entry_count = dir.list_dir(trusted_dir, entries, 32) + let entries = res.unwrap_or(dir.list_dir(trusted_dir), new [string](0)) + let entry_count = entries.length() mut i = 0 while i < entry_count and key_count < 64 @@ -327,8 +328,8 @@ // Get keys from keyring directory if dir.dir_exists(keyring_dir) - mut entries: [string] = new [string](32) - let entry_count = dir.list_dir(keyring_dir, entries, 32) + let entries = res.unwrap_or(dir.list_dir(keyring_dir), new [string](0)) + let entry_count = entries.length() mut i = 0 while i < entry_count and key_count < 64 diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/archive.reef --- a/src/util/archive.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/archive.reef Fri Jul 17 19:04:08 2026 -0500 @@ -22,6 +22,7 @@ import io.dir import io.path import core.str +import core.result as res export // Archive type enumeration (as strings for simplicity) @@ -121,7 +122,7 @@ // Ensure destination directory exists if not dir.dir_exists(dest_dir) - if not dir.create_dir_all(dest_dir) + if not res.is_ok(dir.create_dir_all(dest_dir)) return false end if end if @@ -167,7 +168,7 @@ // Ensure parent directory of output exists let output_dir = path.dirname(output_path) if str.length(output_dir) > 0 and not dir.dir_exists(output_dir) - if not dir.create_dir_all(output_dir) + if not res.is_ok(dir.create_dir_all(output_dir)) return false end if end if @@ -226,7 +227,7 @@ return 0 end if - let content = file.readFile(tmp_file) + let content = res.unwrap_or(file.readFile(tmp_file), "") // Clean up temp file cleanup_temp_file(tmp_file) diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/checksum.reef --- a/src/util/checksum.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/checksum.reef Fri Jul 17 19:04:08 2026 -0500 @@ -21,6 +21,7 @@ import core.str import sys.process import crypto.sha256 as sha +import core.result as res export // Compute SHA256 hash of a file, returns hex string (lowercase) @@ -70,7 +71,7 @@ return "" end if - let hash = str.trim_ws(file.readFile(output_file)) + let hash = str.trim_ws(res.unwrap_or(file.readFile(output_file), "")) // Clean up let rm_pid = process.process_spawn_shell("rm -f \"" + output_file + "\"") diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/http.reef --- a/src/util/http.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/http.reef Fri Jul 17 19:04:08 2026 -0500 @@ -22,6 +22,7 @@ import net.extras import io.file import core.str +import core.result as res import sys.process import util.color @@ -66,7 +67,7 @@ // Download with progress callback let cb = fn(p: http.HttpDownloadProgress): bool => extras.progress_bar(p) - return http.http_download_file_callback(url, dest, cb) + return res.is_ok(http.http_download_file_callback(url, dest, cb)) end download_with_progress // Check if URL will redirect (3xx status) - native HTTP download crashes on redirects @@ -146,12 +147,13 @@ let req = http.http_request_new("GET", url) http.http_request_set_header(req, "User-Agent", "Coral/1.0") - let resp = http.http_send_timeout(req, timeout_ms) + let resp_r = http.http_send_timeout(req, timeout_ms) - // Check for errors - if str.length(resp.error) > 0 + // Check for errors (transport failure is now Err; HttpResponse no longer has an error field) + if res.is_err(resp_r) return "" end if + let resp = res.unwrap_ok(resp_r) // Check for success if not http.http_response_is_ok(resp) @@ -166,11 +168,12 @@ let req = http.http_request_new("HEAD", url) http.http_request_set_header(req, "User-Agent", "Coral/1.0") - let resp = http.http_send_timeout(req, 10000) + let resp_r = http.http_send_timeout(req, 10000) - if str.length(resp.error) > 0 + if res.is_err(resp_r) return false end if + let resp = res.unwrap_ok(resp_r) // Accept success codes and redirects as "reachable" return resp.status_code >= 200 and resp.status_code < 400 @@ -181,11 +184,12 @@ let req = http.http_request_new("HEAD", url) http.http_request_set_header(req, "User-Agent", "Coral/1.0") - let resp = http.http_send_timeout(req, 10000) + let resp_r = http.http_send_timeout(req, 10000) - if str.length(resp.error) > 0 + if res.is_err(resp_r) return 0 end if + let resp = res.unwrap_ok(resp_r) return resp.status_code end get_status diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/mtree.reef --- a/src/util/mtree.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/mtree.reef Fri Jul 17 19:04:08 2026 -0500 @@ -26,6 +26,8 @@ import crypto.sha256 as sha import util.checksum import text.stringbuilder as sb +import core.result as res +import core.option as opt export // Manifest entry representing a single file, directory, or symlink @@ -243,9 +245,9 @@ if not str.equals(current_dir, base_dir) and count < max let rel = get_relative_path(base_dir, current_dir) if not is_metadata_path(rel) - let mode = stat.file_mode(current_dir) - let uid = stat.file_uid(current_dir) - let gid = stat.file_gid(current_dir) + let mode = res.unwrap_or(stat.file_mode(current_dir), 0) + let uid = res.unwrap_or(stat.file_uid(current_dir), 0) + let gid = res.unwrap_or(stat.file_gid(current_dir), 0) entries[count] = ManifestEntry{ epath: "./" + rel, etype: "dir", @@ -260,8 +262,8 @@ end if // List directory contents - mut dir_entries: [string] = new [string](4096) - let entry_count = dir.list_dir(current_dir, dir_entries, 4096) + let dir_entries = res.unwrap_or(dir.list_dir(current_dir), new [string](0)) + let entry_count = dir_entries.length() mut i = 0 while i < entry_count and count < max @@ -284,9 +286,9 @@ // Check type: symlink first (symlinks to dirs would match is_directory) if stat.is_symlink(full_path) - let target = link.readlink(full_path) - let uid = stat.file_uid(current_dir) - let gid = stat.file_gid(current_dir) + let target = res.unwrap_or(link.readlink(full_path), "") + let uid = res.unwrap_or(stat.file_uid(current_dir), 0) + let gid = res.unwrap_or(stat.file_gid(current_dir), 0) entries[count] = ManifestEntry{ epath: "./" + rel, etype: "link", @@ -301,9 +303,9 @@ // Recurse into subdirectory count = walk_directory(base_dir, full_path, entries, count, max) elif stat.is_file(full_path) - let mode = stat.file_mode(full_path) - let uid = stat.file_uid(full_path) - let gid = stat.file_gid(full_path) + let mode = res.unwrap_or(stat.file_mode(full_path), 0) + let uid = res.unwrap_or(stat.file_uid(full_path), 0) + let gid = res.unwrap_or(stat.file_gid(full_path), 0) let hash = checksum.sha256_file(full_path) entries[count] = ManifestEntry{ epath: "./" + rel, @@ -518,13 +520,13 @@ // Resolve a numeric uid to a username. // Uses POSIX getpwuid() via Reef's fs.stat.uid_name() — zero heap allocation. fn uid_to_name(uid: int): string - return stat.uid_name(uid) + return opt.unwrap_or(stat.uid_name(uid), "") end uid_to_name // Resolve a numeric gid to a group name. // Uses POSIX getgrgid() via Reef's fs.stat.gid_name() — zero heap allocation. fn gid_to_name(gid: int): string - return stat.gid_name(gid) + return opt.unwrap_or(stat.gid_name(gid), "") end gid_to_name // Resolve a username to numeric uid by reading /etc/passwd. @@ -534,7 +536,7 @@ return 0 end if - let content = file.readFile("/etc/passwd") + let content = res.unwrap_or(file.readFile("/etc/passwd"), "") if str.length(content) == 0 return 0 end if @@ -564,7 +566,7 @@ return 0 end if - let content = file.readFile("/etc/group") + let content = res.unwrap_or(file.readFile("/etc/group"), "") if str.length(content) == 0 return 0 end if diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/priv.reef --- a/src/util/priv.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/priv.reef Fri Jul 17 19:04:08 2026 -0500 @@ -18,6 +18,7 @@ module util.priv import io.file +import core.result as res export // Check if we are running as root (UID 0) @@ -29,7 +30,8 @@ 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") + // writeFile now returns Result[bool, Error] (Reef 0.7.5); Ok means we wrote it + if res.is_ok(file.writeFile(test_file, "1")) // Successfully wrote - we have root-level access // File will be overwritten next time, no need to delete return true diff -r 8f14ed7e88cb -r 88dbd80325ea src/util/prompt.reef --- a/src/util/prompt.reef Sun Jul 05 18:01:08 2026 -0500 +++ b/src/util/prompt.reef Fri Jul 17 19:04:08 2026 -0500 @@ -18,6 +18,7 @@ module util.prompt import io.console +import core.option as opt import core.str import core.convert import util.color @@ -45,7 +46,7 @@ end if print(message + " [Y/n] ") - let response = console.readLine() + let response = opt.unwrap_or(console.readLine(), "") let r = str.trim_ws(response) // Empty or Y/y means yes