Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/dyndoc/common/file.rb
Class Method Summary collapse
- .old_symlink ⇒ Object
- .old_symlink? ⇒ Object
- .symlink(target_name, link_name) ⇒ Object
- .symlink?(file_name) ⇒ Boolean
Class Method Details
.old_symlink ⇒ Object
25 |
# File 'lib/dyndoc/common/file.rb', line 25 alias_method :old_symlink, :symlink |
.old_symlink? ⇒ Object
26 |
# File 'lib/dyndoc/common/file.rb', line 26 alias_method :old_symlink?, :symlink? |
.symlink(target_name, link_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dyndoc/common/file.rb', line 28 def symlink(target_name, link_name) #if on windows, call mklink, else self.symlink if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/ #windows mklink syntax is reverse of unix ln -s #windows mklink is built into cmd.exe #vulnerable to command injection, but okay because this is a hack to make a cli tool work. opt = (File.directory? target_name) ? "/D" : "" stdin, stdout, stderr, wait_thr = Open3.popen3('cmd.exe', "/c mklink " + opt + "#{link_name} #{target_name}") wait_thr.value.exitstatus else self.old_symlink(target_name, link_name) end end |
.symlink?(file_name) ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dyndoc/common/file.rb', line 42 def symlink?(file_name) #if on windows, call mklink, else self.symlink if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/ #vulnerable to command injection because calling with cmd.exe with /c? stdin, stdout, stderr, wait_thr = Open3.popen3("cmd.exe /c dir #{file_name} | find \"SYMLINK\"") wait_thr.value.exitstatus else self.old_symlink?(file_name) end end |