Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.delete fails with Errno::ENOENT on dangling links #1325

Closed
djberg96 opened this issue Dec 11, 2013 · 2 comments
Closed

File.delete fails with Errno::ENOENT on dangling links #1325

djberg96 opened this issue Dec 11, 2013 · 2 comments

Comments

@djberg96
Copy link
Contributor

On Windows, as on Unix, you can create "dangling" symlinks, i.e. symlinks where the target does not exist.

However, with JRuby you cannot delete a dangling link on Windows. Instead it raises an Errno::ENOENT. You will need the ffi gem to test/verify this:

# symlink.rb
require 'ffi'

class Windows
  extend FFI::Library
  ffi_lib :kernel32

  attach_function :CreateSymbolicLinkA, [:string, :string, :ulong], :bool

  def self.symlink(old_name, new_name)
    # Flip the arguments to match File.symlink
    unless CreateSymbolicLinkA(new_name, old_name, 0) # Assume file
      raise SystemCallError.new('CreateSymbolicLink', FFI.errno)
    end
  end
end

# Please run with elevated privileges.

# Here assume 'bogus.txt' does not exist
Windows.symlink('bogus.txt', 'test_link.txt')
File.delete('test_link.txt') # Works with MRI, fails with JRuby.
@djberg96
Copy link
Contributor Author

Still happening as of JRuby 9.0.5.0.

@djberg96
Copy link
Contributor Author

Stale, closing.

@enebo enebo added this to the Invalid or Duplicate milestone Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants