Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/actions/info.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ fn printInfo(

try t.writer.print("{s}\n\n", .{pkg.desc.slice(&state.string_state)});

var path_buf: [Io.Dir.max_path_bytes]u8 = undefined;
const path = try std.fmt.bufPrint(&path_buf, "/opt/packa/store/{s}-{f}-{s}", .{
pkg.name.slice(&state.string_state), pkg.version, pkg_id.slice(&state.string_state)[0..32],
});

// TODO: improve message
if (Io.Dir.cwd().access(io, path, .{})) {
try t.setColor(.green);
try t.writer.print("Exists in store\n", .{});
try t.setColor(.reset);
} else |_| {}

Comment on lines +90 to +101

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 6 'Io\.Dir\.access|\.access\(io|catch \|_\|' --glob '*.zig' .
fd -H -t f -g 'build.zig' -g 'build.zig.zon' -g '.zig-version' -g '.tool-versions' . \
  -x rg -n -C 3 'zig|version|minimum' {}

Repository: D-Berg/packa

Length of output: 11127


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- manifest and toolchain references ---'
fd -H -t f . | sort | rg '(^|/)(build\.zig(\.zon)?|\.zig-version|\.tool-versions|README.*)$' | while read -r f; do
  printf '\n### %s\n' "$f"
  sed -n '1,80p' "$f"
done

printf '%s\n' '--- relevant source context ---'
sed -n '1,45p' src/util.zig
sed -n '80,170p' src/actions/info.zig

Repository: D-Berg/packa

Length of output: 9350


🌐 Web query:

Zig std.Io.Dir.access error.NotFound API Zig 0.14 0.15

💡 Result:

In Zig versions 0.14 and 0.15, std.fs.Dir.access is the standard function used to check for the existence or accessibility of a file or directory [1][2]. When the specified path does not exist, this function returns error.FileNotFound [3][2]. API Usage and Best Practices The function signature is pub fn access(dir: Dir, io: Io, sub_path: []const u8, options: AccessOptions) AccessError!void (often accessed via std.fs.cwd().access(...)) [3]. When using this function to check if a file exists, it is critical to handle error.FileNotFound explicitly [2]. A common pitfall is the Time-Of-Check-To-Time-Of-Use (TOCTOU) race condition [1][4]. The official Zig documentation and community best practices strongly advise against using access to check if a file exists before opening it [1][4][2]. Instead, you should simply attempt to open the file and handle the error.FileNotFound result from the open operation itself [1][4][2]. This approach is more robust and prevents potential race conditions between the check and the actual file access [4][2]. Context for Zig 0.14/0.15 Zig has been undergoing significant refactoring of its standard library, including moving toward an updated I/O API [5][6][7]. While std.fs.Dir.access remains a standard component for path testing, some older std.fs methods have been deprecated in favor of newer std.Io equivalents [7]. Always ensure you are checking the latest documentation for your specific Zig version, as the standard library continues to evolve [6]. If you encounter unexpected behavior, such as crashes or panics when passing specific paths (e.g., extremely long paths on Windows), be aware that these may be tracked as specific issues in the Zig issue tracker [8], rather than expected API behavior.

Citations:


🌐 Web query:

site:github.com/ziglang/zig 0.16.0 lib/std/Io/Dir.zig access error.FileNotFound

💡 Result:

In Zig 0.16.0, an error.FileNotFound returned by a function in lib/std/fs/Dir.zig (or lib/std/Io/Dir.zig) indicates that the requested file or directory path does not exist [1][2][3]. This error is a standard member of the error sets for various directory and file operations in the Zig standard library, including AccessError, OpenError, MakeError, and DeleteDirError [1][2][4]. If you are encountering this error when you believe the file should exist, consider the following common causes: 1. Incorrect Path: Verify that the sub_path provided to the function is correct relative to the Dir object being used [3]. 2. Race Conditions: If the file was expected to be created or accessed by another process, it may have been deleted or moved, resulting in a race condition [5][4]. 3. Permissions or Mounts: On some systems, especially when using tools like Wine or specific container environments, path resolution or permission settings can cause unexpected FileNotFound errors [6]. 4. Symlinks: If the path involves a symbolic link, ensure the target of the link exists and is accessible [3]. You can debug this by printing the path being accessed just before the call to ensure it matches your expectations, or by using std.fs.cwd.realpathAlloc(allocator, path) to resolve the absolute path for verification. If the error persists unexpectedly, check your operating system's specific behavior regarding the file system operations involved [6].

Citations:


Report the missing-store result explicitly.

When access returns error.FileNotFound, print an explicit missing status. Propagate or report all other errors instead of treating them as absence.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/info.zig` around lines 90 - 101, Update the access handling in
the path-checking block of the info action to print an explicit missing-store
status for error.FileNotFound, while propagating or reporting any other access
errors instead of ignoring them; preserve the existing green “Exists in store”
output for successful access.

try t.writer.print("{s:<10}", .{"Homepage:"});
try t.writer.print("\x1b[4m", .{}); // underline
try t.writer.print("{s}\n", .{pkg.homepage.slice(&state.string_state)});
Expand All @@ -105,7 +117,6 @@ fn printInfo(

if (pkg.compile_deps.count != 0 or pkg.runtime_deps.count != 0) {
try t.writer.print("{s:<10}{s}\n", .{ "Deps:", "compile(◆), runtime(●)" });
var path_buf: [Io.Dir.max_path_bytes]u8 = undefined;
try printDeps(io, t, pkg_id, state, 0, 0, &path_buf);
}
}
Expand Down