Class: Foobara::FilesGenerator::Symlink

Inherits:
String
  • Object
show all
Defined in:
foobara-files-generator-0.2.4/src/symlink.rb

Class Method Summary collapse

Class Method Details

.supported? ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'src/symlink.rb', line 7

def supported?
  return @supported if defined?(@supported)
  # simplecov:disable-next
  return @supported if @mutex.nil?

  @mutex.synchronize do
    target_path = ".foobara-symlink-test-target"
    symlink_path = ".foobara-symlink-test-link"

    @supported = begin
      FileUtils.rm_f(target_path)
      FileUtils.rm_f(symlink_path)

      File.write(target_path, "hi!")
      File.symlink(target_path, symlink_path)

      File.symlink?(symlink_path)
    # TODO: figure out which of these actually happen in Windows
    # rubocop:disable-next Lint/ShadowedException
    rescue Errno::EACCES, NotImplementedError, SystemCallError
      # TODO: come up with a way to test this
      # simplecov:disable
      false
    # simplecov:enable
    ensure
      FileUtils.rm_f(target_path)
      FileUtils.rm_f(symlink_path)
    end

    @mutex = nil
    @supported
  end
end