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

Class Method Details

.detect_linux_filesystem(path) ⇒ String?

Detect Linux filesystem type

Parameters:

  • path (String)

    Path

Returns:

  • (String, nil)

    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

Parameters:

  • path (String)

    Path

Returns:

  • (String, nil)

    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

Parameters:

  • path (String)

    Path

Returns:

  • (String, nil)

    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.expand_path(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

.featuresHash

Get platform-specific features

Returns:

  • (Hash)

    Feature flags



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: supports_file_permissions?,
  }
end

.filesystem_type(path) ⇒ String?

Get file system type for a path

Parameters:

  • path (String)

    File or directory path

Returns:

  • (String, nil)

    Filesystem type or nil if unknown



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

Returns:

  • (Boolean)

    true if 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

Returns:

  • (Boolean)

    true if macOS



17
18
19
# File 'lib/omnizip/platform.rb', line 17

def self.macos?
  !!RUBY_PLATFORM.include?("darwin")
end

.nameString

Get platform name

Returns:

  • (String)

    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

Parameters:

  • path (String)

    File or directory path

Returns:

  • (Boolean)

    true if NTFS



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

Returns:

  • (Boolean)

    true if xattrs 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

Returns:

  • (Boolean)

    true if POSIX permissions supported



78
79
80
# File 'lib/omnizip/platform.rb', line 78

def self.supports_file_permissions?
  unix?
end

.supports_hardlinks?Boolean

Check if hard links are supported

Returns:

  • (Boolean)

    true if hard links 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

Returns:

  • (Boolean)

    true if NTFS streams supported



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

Returns:

  • (Boolean)

    true if symlinks 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

Returns:

  • (Boolean)

    true if Unix-like (macOS, Linux, BSD, etc.)



31
32
33
# File 'lib/omnizip/platform.rb', line 31

def self.unix?
  !windows?
end

.windows?Boolean

Detect if running on Windows

Returns:

  • (Boolean)

    true if 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)

Returns:

  • (Boolean)

    true if developer mode enabled



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