Method: Overcommit::Utils::FileUtils.readlink

Defined in:
lib/overcommit/utils/file_utils.rb

When the host OS is Windows, uses the dir command to check whether link_name is an NTFS symbolic link. If so, it parses the target from the command output. Otherwise raises an ArgumentError. Delegates to File.readlink if the host OS is not Windows.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/overcommit/utils/file_utils.rb', line 32

def readlink(link_name)
  return File.readlink(link_name) unless Overcommit::OS.windows?

  result = win32_dir_cmd(link_name)

  unless win32_symlink?(result.stdout)
    raise ArgumentError, "#{link_name} is not a symlink"
  end

  # Extract symlink target from output, which looks like:
  #   11/13/2012 12:53 AM <SYMLINK> mysymlink [C:\Windows\Temp\somefile.txt]
  result.stdout[/\[(.+)\]/, 1]
end