Project

General

Profile

Actions

Bug #21177

closed

Sometimes Ruby can create and delete long paths on Windows, but cannot traverse them

Added by deivid (David Rodríguez) 1 day ago. Updated about 16 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x64-mingw-ucrt]
[ruby-core:121276]

Description

In the GitHub Actions environment provided by ruby/setup-ruby with os: windows-2022, one can create directories with long names with no issues. Similarly, one can create files inside these directories, and delete these files and directories explicitly without issues. However, one cannot traverse these directories (Dir.children), and as a result, one cannot delete these directories recursively.

This is a small script to reproduce the problem:

require "fileutils"

longest_possible_component = "b" * 255

# Can create directories with long names
FileUtils.mkdir_p "D:/a/#{longest_possible_component}"
puts "FileUtils.mkdir_p ok"

# Can create files inside them
FileUtils.touch "D:/a/#{longest_possible_component}/c"
puts "FileUtils.touch ok"

# Can delete files inside them
File.delete "D:/a/#{longest_possible_component}/c"
puts "File.delete ok"

# Can delete them
Dir.rmdir "D:/a/#{longest_possible_component}"
puts 'Dir.rmdir ok'

FileUtils.mkdir_p "D:/a/#{longest_possible_component}"
FileUtils.touch "D:/a/#{longest_possible_component}/c"

Dir.children "D:/a/#{longest_possible_component}"
# FileUtils.rm_r "D:/a" raises too

It fails with the following output:

$ ruby windows-bug.rb
  
<internal:dir>:184:in 'Dir.open': Filename too long @ dir_initialize - D:/a/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb (Errno::ENAMETOOLONG)
	from windows-bug.rb:24:in 'Dir.children'
	from windows-bug.rb:24:in '<main>'
FileUtils.mkdir_p ok
FileUtils.touch ok
File.delete ok
Dir.rmdir ok

Note that FileUtils.rm_rf does not raise here because it swallows errors (see https://bugs.ruby-lang.org/issues/18784) but fails to remove the directory too due to this bug.

Looking at sources, I wonder if the explicit raise of ENAMETOOLONG should be removed from here: https://github.com/ruby/ruby/blob/e418ba0928ab96ac645ab42d77af34806d74c20e/win32/win32.c#L1985-L2001, and let the system calls themselves raise it if really necessary?

Actions #1

Updated by deivid (David Rodríguez) 1 day ago

  • Subject changed from Sometimes Ruby can create and delete long paths, but cannot traverse them to Sometimes Ruby can create and delete long paths on Windows, but cannot traverse them
Actions #2

Updated by deivid (David Rodríguez) 1 day ago

  • ruby -v changed from 3.4.2 to ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x64-mingw-ucrt]
Actions #3

Updated by nobu (Nobuyoshi Nakada) about 17 hours ago

  • Status changed from Open to Closed

Applied in changeset git|3278e3b6f3b4252ab05988b000886e3b6f089404.


[Bug #21177] Win32: Allow longer path name

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0