Module: Omnizip::Platform
- Defined in:
- lib/omnizip/platform.rb,
lib/omnizip.rb,
lib/omnizip/platform/ntfs_streams.rb
Overview
Platform detection and capabilities Provides cross-platform compatibility checks
Defined Under Namespace
Modules: NtfsStreams
Class Method Summary collapse
-
.detect_linux_filesystem(path) ⇒ String?
Detect Linux filesystem type.
-
.detect_macos_filesystem(path) ⇒ String?
Detect macOS filesystem type.
-
.detect_windows_filesystem(path) ⇒ String?
Detect Windows filesystem type.
-
.features ⇒ Hash
Get platform-specific features.
-
.filesystem_type(path) ⇒ String?
Get file system type for a path.
-
.linux? ⇒ Boolean
Detect if running on Linux.
-
.macos? ⇒ Boolean
Detect if running on macOS.
-
.name ⇒ String
Get platform name.
-
.ntfs?(path) ⇒ Boolean
Check if path is on NTFS filesystem.
-
.supports_extended_attributes? ⇒ Boolean
Check if extended attributes are supported.
-
.supports_file_permissions? ⇒ Boolean
Check if file permissions are supported.
-
.supports_hardlinks? ⇒ Boolean
Check if hard links are supported.
-
.supports_ntfs_streams? ⇒ Boolean
Check if NTFS alternate streams are supported Only available on Windows with NTFS filesystem.
-
.supports_symlinks? ⇒ Boolean
Check if symbolic links are supported.
-
.unix? ⇒ Boolean
Detect if running on Unix-like system.
-
.windows? ⇒ Boolean
Detect if running on Windows.
-
.windows_developer_mode? ⇒ Boolean
Check Windows Developer Mode (for symlink support).
Class Method Details
.detect_linux_filesystem(path) ⇒ String?
Detect Linux filesystem type
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/omnizip/platform.rb', line 178 def self.detect_linux_filesystem(path) output = `df -T #{path} 2>&1`.lines.last return nil unless output # Format: filesystem type blocks used avail use% mounted parts = output.split parts[1] if parts.size > 1 rescue StandardError nil end |
.detect_macos_filesystem(path) ⇒ String?
Detect macOS filesystem type
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/omnizip/platform.rb', line 163 def self.detect_macos_filesystem(path) output = `df -T #{path} 2>&1`.lines.last return nil unless output # Format: filesystem type blocks used avail capacity mounted parts = output.split parts[1] if parts.size > 1 rescue StandardError nil end |
.detect_windows_filesystem(path) ⇒ String?
Detect Windows filesystem type
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/omnizip/platform.rb', line 147 def self.detect_windows_filesystem(path) # Get drive letter drive = File.(path)[0, 2] return nil unless drive =~ /^[A-Za-z]:$/ # Use fsutil to get filesystem type output = `fsutil fsinfo volumeinfo #{drive} 2>&1` Regexp.last_match(1) if output =~ /File System Name\s*:\s*(\w+)/i rescue StandardError nil end |
.features ⇒ Hash
Get platform-specific features
85 86 87 88 89 90 91 92 93 |
# File 'lib/omnizip/platform.rb', line 85 def self.features { ntfs_streams: supports_ntfs_streams?, symlinks: supports_symlinks?, hardlinks: supports_hardlinks?, extended_attributes: supports_extended_attributes?, file_permissions: , } end |
.filesystem_type(path) ⇒ String?
Get file system type for a path
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/omnizip/platform.rb', line 123 def self.filesystem_type(path) return nil unless File.exist?(path) if windows? detect_windows_filesystem(path) elsif macos? detect_macos_filesystem(path) elsif linux? detect_linux_filesystem(path) end end |
.linux? ⇒ Boolean
Detect if running on Linux
24 25 26 |
# File 'lib/omnizip/platform.rb', line 24 def self.linux? !!RUBY_PLATFORM.include?("linux") end |
.macos? ⇒ Boolean
Detect if running on macOS
17 18 19 |
# File 'lib/omnizip/platform.rb', line 17 def self.macos? !!RUBY_PLATFORM.include?("darwin") end |
.name ⇒ String
Get platform name
38 39 40 41 42 43 44 |
# File 'lib/omnizip/platform.rb', line 38 def self.name return "Windows" if windows? return "macOS" if macos? return "Linux" if linux? "Unknown" end |
.ntfs?(path) ⇒ Boolean
Check if path is on NTFS filesystem
139 140 141 |
# File 'lib/omnizip/platform.rb', line 139 def self.ntfs?(path) filesystem_type(path)&.upcase == "NTFS" end |
.supports_extended_attributes? ⇒ Boolean
Check if extended attributes are supported
71 72 73 |
# File 'lib/omnizip/platform.rb', line 71 def self.supports_extended_attributes? unix? end |
.supports_file_permissions? ⇒ Boolean
Check if file permissions are supported
78 79 80 |
# File 'lib/omnizip/platform.rb', line 78 def self. unix? end |
.supports_hardlinks? ⇒ Boolean
Check if hard links are supported
64 65 66 |
# File 'lib/omnizip/platform.rb', line 64 def self.supports_hardlinks? true # Supported on all modern platforms end |
.supports_ntfs_streams? ⇒ Boolean
Check if NTFS alternate streams are supported Only available on Windows with NTFS filesystem
50 51 52 |
# File 'lib/omnizip/platform.rb', line 50 def self.supports_ntfs_streams? windows? end |
.supports_symlinks? ⇒ Boolean
Check if symbolic links are supported
57 58 59 |
# File 'lib/omnizip/platform.rb', line 57 def self.supports_symlinks? unix? || (windows? && windows_developer_mode?) end |
.unix? ⇒ Boolean
Detect if running on Unix-like system
31 32 33 |
# File 'lib/omnizip/platform.rb', line 31 def self.unix? !windows? end |
.windows? ⇒ Boolean
Detect if running on Windows
10 11 12 |
# File 'lib/omnizip/platform.rb', line 10 def self.windows? !!(RUBY_PLATFORM =~ /mswin|mingw|cygwin/) end |
.windows_developer_mode? ⇒ Boolean
Check Windows Developer Mode (for symlink support)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/omnizip/platform.rb', line 98 def self.windows_developer_mode? return false unless windows? # Check registry for developer mode setting # HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock # AllowDevelopmentWithoutDevLicense = 1 begin require "win32/registry" Win32::Registry::HKEY_LOCAL_MACHINE.open( 'SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock', Win32::Registry::KEY_READ, ) do |reg| value = reg["AllowDevelopmentWithoutDevLicense"] return value == 1 end rescue LoadError, StandardError # win32/registry not available or key doesn't exist false end end |