ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:121276] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths, but cannot traverse them
@ 2025-03-10 19:44 deivid via ruby-core
  2025-03-11 17:18 ` [ruby-core:121298] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths on Windows, " deivid via ruby-core
  0 siblings, 1 reply; 2+ messages in thread
From: deivid via ruby-core @ 2025-03-10 19:44 UTC (permalink / raw)
  To: ruby-core; +Cc: deivid

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/win32/win32.c#L1985-L2001, and let the system calls themselves raise it if really necessary?



-- 
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.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:121298] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths on Windows, but cannot traverse them
  2025-03-10 19:44 [ruby-core:121276] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths, but cannot traverse them deivid via ruby-core
@ 2025-03-11 17:18 ` deivid via ruby-core
  0 siblings, 0 replies; 2+ messages in thread
From: deivid via ruby-core @ 2025-03-11 17:18 UTC (permalink / raw)
  To: ruby-core; +Cc: deivid

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/win32/win32.c#L1985-L2001, and let the system calls themselves raise it if really necessary?



-- 
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.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-11 17:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-10 19:44 [ruby-core:121276] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths, but cannot traverse them deivid via ruby-core
2025-03-11 17:18 ` [ruby-core:121298] [Ruby master Bug#21177] Sometimes Ruby can create and delete long paths on Windows, " deivid via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).