diff --git a/lib/path_list/candidate/jruby_windows_fix.rb b/lib/path_list/candidate/jruby_windows_fix.rb index 2acf719..0a08939 100644 --- a/lib/path_list/candidate/jruby_windows_fix.rb +++ b/lib/path_list/candidate/jruby_windows_fix.rb @@ -3,28 +3,18 @@ class PathList class Candidate # @api private module JrubyWindowsFix - # @return [Boolean] whether this path is a directory (false for symlinks to directories) - def directory? - return @directory unless @directory.nil? - - @directory = if ::File.symlink?(@full_path) - false - else - ::File.directory?(@full_path) || false - end - end - - # @return [Boolean] whether this path exists - def exists? - return @exists if defined?(@exists) - - ::File.exist?(@full_path) - end - private def ftype - raise 'File.ftype follows symlinks in jruby in windows' + return @ftype if @ftype + + @ftype = if ::File.symlink?(@full_path) + "link" + else + ::File.ftype(@full_path) + end + rescue ::SystemCallError + @ftype = 'error' end end end diff --git a/spec/path_list_spec.rb b/spec/path_list_spec.rb index 0061f31..5e15bba 100644 --- a/spec/path_list_spec.rb +++ b/spec/path_list_spec.rb @@ -40,8 +40,8 @@ it 'copes with being given fs root' do whatever_file_we_get = subject.each('/').first expect(whatever_file_we_get).not_to start_with('/') - # use ftype because it could be a symlink to nowhere and File.exist? will be sad - expect { File.ftype("/#{whatever_file_we_get}") }.not_to raise_error(Errno::ENOENT) + # use symlink? because it could be a symlink to nowhere and File.exist? would return false + expect { File.symlink?("/#{whatever_file_we_get}") || File.exist?("/#{whatever_file_we_get}") }.not_to raise_error end it 'copes with being given nonsense root' do