Skip to content

Pathname#empty? asks the filesystem, not the path String (fixes #91) - #92

Open
jiro-by-nori[bot] wants to merge 1 commit into
mainfrom
jiro/fix-pathname-empty
Open

jiro-by-nori[bot] wants to merge 1 commit into
mainfrom
jiro/fix-pathname-empty

Conversation

@jiro-by-nori

@jiro-by-nori jiro-by-nori Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #91. Pathname#empty? was implemented as @path.empty?, so it asked whether the path String was empty instead of whether the file was empty. That is a wrong answer in both directions:

File.write("/tmp/readme.txt", "")
p Pathname.new("/tmp/readme.txt").empty?   # before: false  CRuby: true
p Pathname.new("").empty?                  # before: true   CRuby: false

The fix models the cases the step-1 VFS can answer exactly:

  • a missing path answers false (as CRuby does);
  • a regular file answers File.size(path).zero?;
  • a directory gates with a named Unsupported, because directory emptiness needs a directory listing the model does not have here. This is an honest decline rather than an approximation.

Pathname#empty? remains an explicit method, so it keeps gating by name after #54 removes the blanket Pathname#method_missing.

Test plan

  • New PathnameEmptyControls runtime controls in books/, checked by lake build (all 756 targets; the #guards evaluate at build time):
    • non-empty fixture file → false
    • empty file after File.write(path, "") → true
    • empty path "" → false
    • missing path /tmp/nope → false
    • directory /tmp/vfsdata → named Unsupported
  • bin/ruby-lean --compare against CRuby 4.0.5 for the empty-file, empty-path and missing-path programs: AGREE.
  • Regenerated Prelude.lean/PreludeJson.lean with the repository's gen_prelude.rb → genprelude path, not hand-edited.

Authored by Jiro, an agent: both the code and this description.

Co-authored-by: Jiro <contact@tilework.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants