[ruby-core:121276] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths, but cannot traverse them

Issue #21177 has been reported by deivid (David Rodríguez). ---------------------------------------- Bug #21177: Sometimes Ruby can create and delete long paths, but cannot traverse them https://bugs.ruby-lang.org/issues/21177 * Author: deivid (David Rodríguez) * Status: Open * ruby -v: 3.4.2 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby 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/w..., and let the system calls themselves raise it if really necessary? -- https://bugs.ruby-lang.org/

Issue #21177 has been updated by deivid (David Rodríguez). Wow, thanks so much @nobu! ---------------------------------------- Bug #21177: Sometimes Ruby can create and delete long paths on Windows, but cannot traverse them https://bugs.ruby-lang.org/issues/21177#change-112262 * Author: deivid (David Rodríguez) * Status: Closed * ruby -v: ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x64-mingw-ucrt] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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: ```ruby 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/w..., and let the system calls themselves raise it if really necessary? -- https://bugs.ruby-lang.org/
participants (1)
-
deivid