HEX
Server: Apache
System: Linux hp3-stn-1011028.hostingp3.local 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: csh958633 (951153)
PHP: 8.3.30
Disabled: shell_exec,exec,system,popen,set_time_limit
Upload Files
File: //usr/share/ruby/vendor_ruby/puppet/file_system/path_pattern.rb
require 'pathname'

module Puppet::FileSystem
  class PathPattern
    class InvalidPattern < Puppet::Error; end

    TRAVERSAL = /^\.\.$/
    ABSOLUTE_UNIX = /^\//
    ABSOLUTE_WINDOWS = /^[a-z]:/i
    #ABSOLUT_VODKA #notappearinginthisclass
    CURRENT_DRIVE_RELATIVE_WINDOWS = /^\\/

    def self.relative(pattern)
      RelativePathPattern.new(pattern)
    end

    def self.absolute(pattern)
      AbsolutePathPattern.new(pattern)
    end

    class << self
      protected :new
    end

    # @param prefix [AbsolutePathPattern] An absolute path pattern instance
    # @return [AbsolutePathPattern] A new AbsolutePathPattern prepended with
    #   the passed prefix's pattern.
    def prefix_with(prefix)
      new_pathname = prefix.pathname + pathname
      self.class.absolute(new_pathname.to_s)
    end

    def glob
      Dir.glob(pathname.to_s)
    end

    def to_s
      pathname.to_s
    end

    protected

    attr_reader :pathname

    private

    def validate
      @pathname.each_filename do |e|
        if e =~ TRAVERSAL
          raise(InvalidPattern, "PathPatterns cannot be created with directory traversals.")
        end
      end
      case @pathname.to_s
      when CURRENT_DRIVE_RELATIVE_WINDOWS
        raise(InvalidPattern, "A PathPattern cannot be a Windows current drive relative path.")
      end
    end

    def initialize(pattern)
      begin
        @pathname = Pathname.new(pattern.strip)
      rescue ArgumentError => error
        raise InvalidPattern.new("PathPatterns cannot be created with a zero byte.", error)
      end
      validate
    end
  end

  class RelativePathPattern < PathPattern
    def absolute?
      false
    end

    def validate
      super
      case @pathname.to_s
      when ABSOLUTE_WINDOWS
        raise(InvalidPattern, "A relative PathPattern cannot be prefixed with a drive.")
      when ABSOLUTE_UNIX
        raise(InvalidPattern, "A relative PathPattern cannot be an absolute path.")
      end
    end
  end

  class AbsolutePathPattern < PathPattern
    def absolute?
      true
    end

    def validate
      super
      if @pathname.to_s !~ ABSOLUTE_UNIX and @pathname.to_s !~ ABSOLUTE_WINDOWS
        raise(InvalidPattern, "An absolute PathPattern cannot be a relative path.")
      end
    end
  end
end