[ruby-core:121298] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths on Windows, but cannot traverse them
From:
deivid via ruby-core <ruby-core@...>
Date:
2025-03-11 17:18:29 UTC
List:
ruby-core #121298
Issue #21177 has been updated by deivid (David Rodr=EDguez).
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=EDguez)
* 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: w=
indows-2022`, one can create directories with long names with no issues. Si=
milarly, one can create files inside these directories, and delete these fi=
les and directories explicitly without issues. However, one cannot traverse=
these directories (`Dir.children`), and as a result, one cannot delete the=
se directories recursively.
This is a small script to reproduce the problem:
```ruby
require "fileutils"
longest_possible_component =3D "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
=20
<internal:dir>:184:in 'Dir.open': Filename too long @ dir_initialize - D:/a=
/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb=
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb=
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb=
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb (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 direc=
tory 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/e418ba0928ab96ac64=
5ab42d77af34806d74c20e/win32/win32.c#L1985-L2001, and let the system calls =
themselves raise it if really necessary?
--=20
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.rub=
y-lang.org/