<commit_before>require 'logger'
require 'yaml'

class ImageMetadata
  def initialize(tarball: nil, env: nil, logger: nil)
    @tarball = tarball
    @env = env
    @logger = logger
    @env_hash = nil
    @files = {}
  end

  def to_s
    tarball
  end

  def parent_dir
    @parent_dir ||= File.dirname(File.expand_path(tarball))
  end

  def valid?
    !tarball.nil? && File.exist?(tarball)
  end

  def load!
    extract_tarball
    load_job_board_register_yml
    load_image_metadata

    @env_hash = env.to_hash
    @files = {}

    dir.children.reject(&:directory?).each do |p|
      @files[p.basename.to_s] = p
    end
  end

  attr_reader :env_hash, :files

  private
<commit_msg>Insulate image metadata loading from nonexistent paths<commit_after>require 'logger'
require 'yaml'

class ImageMetadata
  def initialize(tarball: nil, env: nil, logger: nil)
    @tarball = tarball
    @env = env
    @logger = logger
    @env_hash = nil
    @files = {}
  end

  def to_s
    tarball
  end

  def parent_dir
    @parent_dir ||= File.dirname(File.expand_path(tarball))
  end

  def valid?
    !tarball.nil? && File.exist?(tarball)
  end

  def load!
    extract_tarball
    load_job_board_register_yml
    load_image_metadata

    @env_hash = env.to_hash
    @files = {}

    return unless dir.exist?

    dir.children.reject { |c| !c.exist? || c.directory? }.each do |p|
      @files[p.basename.to_s] = p
    end
  end

  attr_reader :env_hash, :files

  private

{'fraction_non_alphanumeric': 0.10497614178595774, 'fraction_numerical': 0.0, 'mean_word_length': 2.8835978835978837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7019252', 'n_tokens_mistral': 540, 'n_tokens_neox': 520, 'n_words': 125}