Skip to content

Commit

Permalink
fixup! Use ftype
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Nov 22, 2023
1 parent a395807 commit 08c3e7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
28 changes: 9 additions & 19 deletions lib/path_list/candidate/jruby_windows_fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/path_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08c3e7b

Please sign in to comment.