Repository navigation
file/dir: File::Stat surface, File.ftype, aliases, errno mapping + Dir Enumerable/enumerators (core/file +22, core/dir +29) - #591
Merged
Conversation
…enumerators (core/file +20, core/dir +29) Advance MRI-Ruby-4.0.x conformance of File and Dir (offline-fixable), verified byte-for-byte against ruby 4.0.5. File (internal/vm/file.go): - Add File.ftype (lstat-based, #to_path arg, ArgumentError arity, Errno::ENOENT) — ruby/ruby v3_4_0 file.c rb_file_s_ftype. - Add File::Separator (mixed-case alias of File::SEPARATOR). - File.chmod / File.umask coerce the mode via #to_int and raise RangeError for a Bignum that overflows a C long (num2mode, mirroring NUM2MODET); File.umask raises ArgumentError for >1 argument. - File.rename checks its two-argument arity before coercing (ArgumentError, not a TypeError). - File.truncate maps a negative length to Errno::EINVAL (truncate(2)). - File.exist?/file? (oneArg) and File.identical? enforce their arity. - File.unlink is a genuine alias of File.delete, File.empty? of File.zero? (shared Method records, so File.method(:unlink) == File.method(:delete)). - File.realpath / File.realdirpath raise Errno::ELOOP for a symlink loop instead of Errno::ENOENT (raiseRealpathErr). Dir (internal/vm/dir.go): - Path-taking singletons (entries/children/exist?/empty?/chdir/each_child/ foreach/delete) coerce via rb_get_path (#to_path/#to_str) instead of rejecting a non-String with a TypeError. - Dir.getwd is a genuine alias of Dir.pwd; Dir.rmdir and Dir.unlink of Dir.delete. - Dir includes Enumerable (deferred to post-prelude includeDirEnumerable, since registerDir runs before the prelude defines the module). - Dir.delete enforces rmdir(2) errnos: Errno::ENOTDIR for a non-directory, Errno::ENOTEMPTY for a non-empty directory, Errno::EACCES for a permission failure (raiseRmdirErr) — was always Errno::ENOENT. - Dir.each_child / Dir.foreach with no block return a nil-#size Enumerator instead of dereferencing a nil block (was a crash); Dir#each / Dir#each_child likewise return nil-#size enumerators. - Add Dir#children and Dir#chdir instance methods (Ruby 2.5+/3.5+). Out of scope (noted for follow-up): the lexer mis-parses `%w[]` escaped-space words (splits `a\ b` into two), which fabricates a stray top-level entry in the Dir spec fixtures and confounds several ordering/glob examples; File# instance metadata methods (stat/lstat/mtime/atime/ctime/birthtime/flock) live in io.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add internal/vm/wave19_filedir_internal_test.go exercising every new File/Dir branch against MRI-verified values (ftype, num2mode, umask/chmod coercion, predicate arity, rename arity, truncate errno, realpath/realdirpath ELOOP, Dir path coercion + Enumerable, Dir.delete errno mapping, class/instance enumerators, Dir#children/#chdir, aliases). go tool cover -func reports 100% on file.go, dir.go and filestat.go. Fix ELOOP detection: filepath.EvalSymlinks returns a bare "too many links" error that does not wrap syscall.ELOOP, so realpath/realdirpath re-stat the path (os.Stat surfaces the kernel's ELOOP) via isSymlinkLoop — verified against ruby 4.0.5 for a self-referential symlink. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nk deps) Cover raiseRmdirErr (EACCES/ENOTEMPTY/ENOENT) with synthetic os.PathErrors and raiseRealpathErr/isSymlinkLoop (ELOOP/ENOENT) through the osStat seam, reusing the shared expectRaise helper. This keeps 100% coverage of the errno mapping without relying on running as an unprivileged user or on real symlink cycles, so the coverage gate holds regardless of the CI environment. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TestFileTruncateErrno (truncate(-1) => EINVAL) and TestDirDeleteErrno (delete(nonempty) => ENOTEMPTY) assert POSIX errnos; Windows reports ENOENT for both, failing the windows lane. Guard those two assertions with runtime.GOOS != "windows" (the 100% coverage gate runs on the POSIX lanes, so coverage is unaffected); the other errno cases (ENOENT/ENOTDIR) hold on Windows. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…594) Wave-19 merged three bibliography-first conformance PRs: - #593 core/io: pread/pwrite, sysopen, dup, initialize/reopen, to_io/path/ inspect, set_encoding, ungetbyte, lineno, sysread, std-stream halves — +56. - #591 core/file+dir: File::Stat surface, ftype, chmod/umask/truncate/rename errno + coercion, realpath ELOOP, Dir Enumerable + entries/children/foreach/ each_child (fixing a nil-pointer crash) — core/file +22, core/dir +29. - #592 core/kernel: respond_to?/eql?/remove_instance_variable mirrored on Kernel, then/yield_self blockless Enumerator — +8. Measured total on merged main: 19773 passing. Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances MRI-Ruby-4.0.x conformance of
FileandDirfor the offline-fixableremainder of
core/fileandcore/dir, verified byte-for-byte againstruby4.0.5. Bibliography: ruby/ruby
v3_4_0file.c/dir.c, and ruby/spec undercore/fileandcore/dir.Measured deltas (ruby/spec, this corpus)
core/filecore/dirNet +51 passing examples. FLOOR is untouched.
File (
internal/vm/file.go)File.ftype— added (rb_file_s_ftype): lstat-based (a symlink is"link", not its target),#to_pathargument,ArgumentErrorfor a wrongarity,
Errno::ENOENTfor a missing path.File::Separator— added (mixed-case alias ofFile::SEPARATOR).File.chmod/File.umask— coerce the mode via#to_intand raiseRangeErrorfor a Bignum that overflows a C long (num2mode, mirroringNUM2MODET), instead of aTypeError;File.umaskraisesArgumentErrorfor more than one argument.
File.rename— checks its two-argument arity before coercing paths(
ArgumentError, not aTypeError).File.truncate— maps a negative length toErrno::EINVAL(truncate(2)),keeping
Errno::ENOENTfor a missing path.File.exist?/File.file?/File.identical?— enforce their arity(
ArgumentError).File.unlink/File.empty?— genuine aliases ofFile.delete/File.zero?(sharedMethodrecords, soFile.method(:unlink) == File.method(:delete)).File.realpath/File.realdirpath— raiseErrno::ELOOPfor a symlinkcycle instead of
Errno::ENOENT.filepath.EvalSymlinksreturns a bare"too many links" error that does not wrap
syscall.ELOOP, so the real errnois recovered by re-stating the path (
isSymlinkLoop).Dir (
internal/vm/dir.go)Dir.entries/children/exist?/empty?/chdir/each_child/foreach/deletenow userb_get_path(
#to_path/#to_str) instead of rejecting a non-String with aTypeError.Dir.getwdis a genuine alias ofDir.pwd;Dir.rmdirandDir.unlinkofDir.delete.DirincludesEnumerable— deferred to a post-preludeincludeDirEnumerable(registerDir runs before the prelude defines themodule), so
Dir.include?(Enumerable)andEnumerablemethods (to_a, …)work on an open
Dir.Dir.deleteerrno mapping —Errno::ENOTDIRfor a non-directory,Errno::ENOTEMPTYfor a non-empty directory,Errno::EACCESfor apermission failure (
raiseRmdirErr); it was alwaysErrno::ENOENT.Dir.each_child/Dir.foreachwith no block nowreturn an
Enumeratorwhose#sizeisnilinstead of dereferencing a nilblock (was a crash);
Dir#each/Dir#each_childlikewise returnnil-#sizeenumerators.Dir#childrenandDir#chdir.Tests & gates
internal/vm/wave19_filedir_internal_test.goasserts everynew branch against MRI-verified values.
go tool cover -funcreports 100%on
file.go,dir.goandfilestat.go. The errno-classification helpers arecovered deterministically (synthetic
os.PathErrors and theosStatseam),so the coverage gate does not depend on running unprivileged or on real
symlink cycles.
go build ./...,GOWORK=off go test ./...,gofmt -l internal/vm/(clean),and the
wasip1(GOOS=wasip1 GOARCH=wasm) andwindowscross-builds allpass. OS-specific tests are guarded by
runtime.GOOS.Deliberately out of scope (noted for follow-up owners)
%w[]escaped-space lexing (lexer, not in this file set):%w[a\ b]splits into two words instead of one. This fabricates a stray top-level entry
in the shared
Dirspec fixtures (special/test\ +()[]{}→ a phantom+()[]{}directory) and confounds severalDirordering/glob examples thatotherwise now have correct behaviour.
File#instance metadata (stat/lstat/mtime/atime/ctime/birthtime/flock, andFile#chmodto_int/RangeError) lives inio.go,which this task does not touch.
File.mkfifois intentionally NOT added: it would makeopen_spec.rb'sthreaded FIFO example reachable, which deadlocks under rbgo's current
Thread/blocking-open model (a real MRI passes it) and would turn that file's
~50 passes into a per-file timeout — a net regression. The blocking-FIFO
limitation is in the IO/threading layer.
File.basenameencoding preservation,File.expand_pathEncoding::CompatibilityErrorfromdefault_external) andFile.fnmatchFNM_EXTGLOBbrace handling live outside this file set.🤖 Generated with Claude Code