DRIVER=serial8250
MODALIAS=platform:serial8250
     ˆÃÂÈ570Á¿Æ :    ‹      Í•Ao›0Åïýž»Á’¬�R`êB¥EK“(Í4MÓ›`0²MXöégB¢°)Y[-ªzÁÆ~Ø¿÷ŒmïM8-¿ÍoÑ§åÝÍ¿|œŒG[ _û#€p¶Ûqn§áTërP×µ]÷m!W°\@ªól JKk›jŠƒ¯i.�—2BM‰<ÍuÆ‚qAÙO$¢ÒŠSfF.«(ãñ¾¨È(VÐ„gÌ¦,vªìXˆÒLDE¬,¥²½ÚL»QgD)àEYi`kVèP¶æ1UEF Y¹¨s<h9ìÐ¼HÐMCì¾:±‹D[È¦*O§hM2¾*|¬E‰�ç+¤dìcà±(D)ìO0"™öñ÷ñhöÃè@§Í×�GP*Yâã#z=óCLIÎ< Ç5wFsƒƒ	Qå‚ò„3zR|ßŠïù¯Ó†­&d*–¼Ô\)‹]«±ÈTIŒ×wÆA*»ªVBKƒÄ„1¿YÜN—áxÑFB›!t/¾Ö8˜iºPÈ%‹µ�›]-ØÛ"RåõþíœJ¾J5²ÐQå3â©Š‡BÔE7!“þÑl;Ì£øQÏé]ZnÏrzÈ}?t.:!4§ÈçÿEODF™ì’ŸZÕ]ê[ú¦ò¨×ê;È½®N:8GøOwPŠšIc -Ï±/Ëßýáõ×²ÏØÕv#ã -Ïaàß[á‰G!ì.	¶˜í•û—-9�Õ    E   ˆl–Ãa¾”ªi?u8 ¸Û71hß�þDÈßYÇÌc!Zq§žþÊƒ|"É_�uÐb&=LyZËcõÁÈ #©    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

class Sessions::Store::File
  def initialize
    # get application root directory
    @root = Dir.pwd.to_s
    if @root.blank? || @root == '/'
      @root = Rails.root
    end

    # get working directories
    @path = "#{@root}/tmp/websocket_#{Rails.env}"
    @nodes_path = "#{@root}/tmp/session_node_#{Rails.env}"
  end

  def create(client_id, content)
    path = safe_session_path(client_id)

    # The login creates the session of a connected client again. Destroying it first would let a
    #   concurrent #get find the directory without its file, take it as broken and destroy the new one.
    return if File.exist?(path) && replace_session_file(path, content)

    path_tmp     = File.join(@path, 'tmp', File.basename(path))
    session_file = File.join(path_tmp, 'session')

    # store session data in session file
    FileUtils.mkpath path_tmp
    File.binwrite(session_file, content)

    # move to destination directory
    FileUtils.mv(path_tmp, path)
  end

  def sessions
    path = "#{@path}/"

    FileUtils.mkdir_p path

    data = []
    Dir.foreach(path) do |entry|
      next if entry == '.'
      next if entry == '..'
      next if entry == 'tmp'
      next if entry == 'spool'

      data.push entry.to_s
    end
    data
  end

  def session_exists?(client_id)
    session_dir = safe_session_path(client_id)
    return false if !File.exist?(session_dir)

    session_file = "#{session_dir}/session"
    return false if !File.exist?(session_file)

    true
  end

  def destroy(client_id)
    path = safe_session_path(client_id)
    FileUtils.rm_rf path

    # forked sessions workers
    Dir.glob("#{@nodes_path}/*.#{client_id}.session").each { FileUtils.rm_rf it }
  end

  def set(client_id, data)
    path = safe_session_path(client_id)
    write_with_lock("#{path}/session", data.to_json)
  end

  def get(client_id)
    session_dir  = safe_session_path(client_id)
    session_file = "#{session_dir}/session"
    data         = nil

    return if !check_session_file_for_client(client_id, session_dir, session_file)

    begin
      data_json = JSON.parse(read_with_lock(session_file))
      if data_json
        data        = Sessions.symbolize_keys(data_json)
        data[:user] = data_json['user'] # for compat. reasons
      end
    rescue => e
      Sessions.log('error', e.inspect)
      destroy(client_id)
      Sessions.log('error', "error in reading/parsing session file '#{session_file}', remove session.")
      return
    end
    data
  end

  def get_many(client_ids)
    client_ids.each_with_object({}) do |client_id, result|
      data = get(client_id)
      result[client_id] = data if data
    end
  end

  def send_data(client_id, data)
    location = new_message_filename_for(client_id)
    return false if !location

    begin
      write_with_lock(location, data.to_json)
    rescue => e
      Sessions.log('error', e.inspect)
      Sessions.log('error', "error in writing message file '#{location}'")
      return false
    end
    true
  end

  def send_data_many(entries)
    entries.each do |client_id, data|
      send_data(client_id, data)
    end
  end

  def queue(client_id)
    path  = "#{safe_session_path(client_id)}/"
    data  = []
    files = []
    Dir.foreach(path) do |entry|
      next if entry == '.'
      next