class ChefConfig::PathHelper

def self.dirname(path, windows: ChefUtils.windows?)

def self.dirname(path, windows: ChefUtils.windows?)
  if windows
    # Find the first slash, not counting trailing slashes
    end_slash = path.size
    loop do
      slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator(windows: windows))}]/, end_slash - 1)
      if !slash
        return end_slash == path.size ? "." : path_separator(windows: windows)
      elsif slash == end_slash - 1
        end_slash = slash
      else
        return path[0..slash - 1]
      end
    end
  else
    ::File.dirname(path)
  end
end