Module: Overcommit::Utils::FileUtils
- Defined in:
- lib/overcommit/utils/file_utils.rb
Overview
Utility functions for file IO.
Class Method Summary collapse
-
.readlink(link_name) ⇒ Object
When the host OS is Windows, uses the
dircommand to check whetherlink_nameis an NTFS symbolic link. -
.symlink(old_name, new_name) ⇒ Object
When the host OS is Windows, uses the
mklinkcommand to create an NTFS symbolic link fromnew_nametoold_name. -
.symlink?(file_name) ⇒ Boolean
When the host OS is Windows, uses the
dircommand to check whetherfile_nameis an NTFS symbolic link.
Class Method Details
.readlink(link_name) ⇒ Object
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 |
.symlink(old_name, new_name) ⇒ Object
When the host OS is Windows, uses the mklink command to create an NTFS symbolic link from new_name to old_name. Otherwise delegates to File.symlink
11 12 13 14 15 16 |
# File 'lib/overcommit/utils/file_utils.rb', line 11 def symlink(old_name, new_name) return File.symlink(old_name, new_name) unless Overcommit::OS.windows? result = win32_mklink_cmd(old_name, new_name) result.status end |
.symlink?(file_name) ⇒ Boolean
When the host OS is Windows, uses the dir command to check whether file_name is an NTFS symbolic link. Otherwise delegates to File.symlink.
21 22 23 24 25 26 |
# File 'lib/overcommit/utils/file_utils.rb', line 21 def symlink?(file_name) return File.symlink?(file_name) unless Overcommit::OS.windows? result = win32_dir_cmd(file_name) win32_symlink?(result.stdout) end |