Module: Omnizip::LinkHandler
- Defined in:
- lib/omnizip/link_handler.rb,
lib/omnizip/link_handler/hard_link.rb,
lib/omnizip/link_handler/symbolic_link.rb
Overview
Handles symbolic and hard link operations with platform detection
Defined Under Namespace
Classes: HardLink, SymbolicLink
Class Method Summary collapse
-
.create_hardlink(target, link_path) ⇒ Object
Create a hard link.
-
.create_symlink(target, link_path) ⇒ Object
Create a symbolic link.
-
.detect_link(path) ⇒ Object
Detect the type of link (or nil if not a link).
-
.hard_link_from_path(path, original_path) ⇒ Object
Create a HardLink instance from a filesystem path.
-
.hardlink?(path) ⇒ Boolean
Detect if a path is a hard link.
-
.hardlink_supported? ⇒ Boolean
Check if hard links are supported.
-
.inode_number(path) ⇒ Object
Get inode number for hard link tracking.
-
.read_link_target(link_path) ⇒ Object
Read the target of a symbolic link.
-
.supported? ⇒ Boolean
Check if the platform supports symbolic links.
-
.symbolic_link_from_path(path) ⇒ Object
Create a SymbolicLink instance from a filesystem path.
-
.symlink?(path) ⇒ Boolean
Detect if a path is a symbolic link.
-
.symlink_supported? ⇒ Boolean
Check if symbolic links are supported on this platform.
Class Method Details
.create_hardlink(target, link_path) ⇒ Object
Create a hard link
72 73 74 75 76 77 78 79 80 |
# File 'lib/omnizip/link_handler.rb', line 72 def create_hardlink(target, link_path) unless hardlink_supported? raise Omnizip::Error, "Hard links are not supported on #{RUBY_PLATFORM}" end FileUtils.mkdir_p(File.dirname(link_path)) File.link(target, link_path) end |
.create_symlink(target, link_path) ⇒ Object
Create a symbolic link
61 62 63 64 65 66 67 68 69 |
# File 'lib/omnizip/link_handler.rb', line 61 def create_symlink(target, link_path) unless symlink_supported? raise Omnizip::Error, "Symbolic links are not supported on #{RUBY_PLATFORM}" end FileUtils.mkdir_p(File.dirname(link_path)) File.symlink(target, link_path) end |
.detect_link(path) ⇒ Object
Detect the type of link (or nil if not a link)
52 53 54 55 56 57 58 |
# File 'lib/omnizip/link_handler.rb', line 52 def detect_link(path) return nil unless supported? return :symlink if symlink?(path) return :hardlink if hardlink?(path) nil end |
.hard_link_from_path(path, original_path) ⇒ Object
Create a HardLink instance from a filesystem path
111 112 113 114 115 116 117 118 119 |
# File 'lib/omnizip/link_handler.rb', line 111 def hard_link_from_path(path, original_path) return nil unless hardlink?(path) HardLink.new( target: original_path, path: path, inode: inode_number(path), ) end |
.hardlink?(path) ⇒ Boolean
Detect if a path is a hard link
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/omnizip/link_handler.rb', line 40 def hardlink?(path) return false unless hardlink_supported? return false unless File.exist?(path) return false if File.directory?(path) stat = File.stat(path) stat.nlink > 1 rescue StandardError false end |
.hardlink_supported? ⇒ Boolean
Check if hard links are supported
26 27 28 |
# File 'lib/omnizip/link_handler.rb', line 26 def hardlink_supported? supported? && Omnizip::Platform.supports_hardlinks? end |
.inode_number(path) ⇒ Object
Get inode number for hard link tracking
93 94 95 96 97 98 99 100 |
# File 'lib/omnizip/link_handler.rb', line 93 def inode_number(path) return nil unless hardlink_supported? return nil unless File.exist?(path) File.stat(path).ino rescue StandardError nil end |
.read_link_target(link_path) ⇒ Object
Read the target of a symbolic link
83 84 85 86 87 88 89 90 |
# File 'lib/omnizip/link_handler.rb', line 83 def read_link_target(link_path) unless symlink_supported? raise Omnizip::Error, "Symbolic links are not supported on #{RUBY_PLATFORM}" end File.readlink(link_path) end |
.supported? ⇒ Boolean
Check if the platform supports symbolic links
12 13 14 |
# File 'lib/omnizip/link_handler.rb', line 12 def supported? !windows_platform? end |
.symbolic_link_from_path(path) ⇒ Object
Create a SymbolicLink instance from a filesystem path
103 104 105 106 107 108 |
# File 'lib/omnizip/link_handler.rb', line 103 def symbolic_link_from_path(path) return nil unless symlink?(path) target = read_link_target(path) SymbolicLink.new(target: target, path: path) end |
.symlink?(path) ⇒ Boolean
Detect if a path is a symbolic link
31 32 33 34 35 36 37 |
# File 'lib/omnizip/link_handler.rb', line 31 def symlink?(path) return false unless symlink_supported? File.symlink?(path) rescue StandardError false end |
.symlink_supported? ⇒ Boolean
Check if symbolic links are supported on this platform. Delegates to Platform but also gates on LinkHandler#supported? (Windows is treated as unsupported here for historical compatibility — even if Windows Developer Mode would allow symlinks, callers should opt into that explicitly via Platform).
21 22 23 |
# File 'lib/omnizip/link_handler.rb', line 21 def symlink_supported? supported? && Omnizip::Platform.supports_symlinks? end |