<commit_before>module Dapp
  module Build
    module Stage
      # Base of all stages
      class Base
        include Helper::Sha256
        include Helper::Trivia
        include Mod::Logging

        attr_accessor :prev_stage, :next_stage
        attr_reader :dimg

        def initialize(dimg, next_stage)
          @dimg = dimg

          @next_stage = next_stage
          @next_stage.prev_stage = self
        end

        # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
        def build_lock!
          return yield if dimg.project.dry_run?

          try_lock = proc do
            next yield unless should_be_tagged?

            no_lock = false

            dimg.project.lock("#{dimg.project.name}.image.#{image.name}") do
              image.cache_reset

              if should_be_tagged?
                yield
              else
                no_lock = true
              end
            end

            yield if no_lock
          end

          if prev_stage
            prev_stage.build_lock! { try_lock.call }
          else
            try_lock.call
          end
        end
        # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity

        def build!
          return if should_be_skipped?
          prev_stage.build! if prev_stage
          if image_should_be_build?
            prepare_image unless image.tagged?
            log_image_build(&method(:image_build))
          end
          dimg.introspect_image!(image: image.built_id, options: image.send(:prepared_options)) if should_be_introspected?
        end

        def save_in_cache!
          prev_stage.save_in_cache! if prev_stage
          return unless should_be_tagged?<commit_msg>modified not_present logic<commit_after>module Dapp
  module Build
    module Stage
      # Base of all stages
      class Base
        include Helper::Sha256
        include Helper::Trivia
        include Mod::Logging

        attr_accessor :prev_stage, :next_stage
        attr_reader :dimg

        def initialize(dimg, next_stage)
          @dimg = dimg

          @next_stage = next_stage
          @next_stage.prev_stage = self
        end

        # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
        def build_lock!
          return yield if dimg.project.dry_run?

          try_lock = proc do
            next yield unless should_be_tagged?

            no_lock = false

            dimg.project.lock("#{dimg.project.name}.image.#{image.name}") do
              image.cache_reset

              if should_be_tagged?
                yield
              else
                no_lock = true
              end
            end

            yield if no_lock
          end

          if prev_stage
            prev_stage.build_lock! { try_lock.call }
          else
            try_lock.call
          end
        end
        # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity

        def build!
          return if should_be_skipped?
          prev_stage.build! if prev_stage
          if image_should_be_build?
            prepare_image if !image.tagged? && !should_be_not_present?
            log_image_build(&method(:image_build))
          end
          dimg.introspect_image!(image: image.built_id, options: image.send(:prepared_options)) if should_be_introspected?
        end

        def save_in_cache!
          prev_stage.save_in_cache! if prev_stage
          return unless should_be_tagged?
{'fraction_non_alphanumeric': 0.05763104546770924, 'fraction_numerical': 0.0017376194613379669, 'mean_word_length': 1.6921278254091972, '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': '5258899', 'n_tokens_mistral': 986, 'n_tokens_neox': 945, 'n_words': 216}