<commit_before>require 'rpm'

module RPM

  class Transaction

    def self.release(ptr)
      RPM::FFI.rpmtsFree(ptr)
    end

    def initialize
      @ts = ::FFI::AutoPointer.new(RPM::FFI.rpmtsCreate, Transaction.method(:release))
      RPM::FFI.rpmtsSetRootDir(@ts, "/")
    end

    def ptr
      @ts
    end
    
    def each
      it = RPM::FFI.rpmtsInitIterator(@ts, 0, nil, 0)
      #STDERR.puts it.class
      while (not (header = RPM::FFI.rpmdbNextIterator(it)).null?)
        yield Header.new(header)
      end
      RPM::FFI.rpmdbFreeIterator(it)
    end

    # Add a install operation to the transaction
    # @param [Package] pkg Package to install
    def install(pkg, key)
      raise TypeError if not pkg.is_a?(RPM::Package)
      
      @keys ||= Array.new
      raise ArgError, "key must be unique" if @keys.include?(key)
      @keys << key
      
      RPM::FFI.rpmtsAddInstallElement(@ts, pkg.ptr, key.to_s, 0, nil)
      nil
    end

    # Sets the root directory for this transaction
    # @param [String] root directory
    def root_dir=(dir)
      rc = RPM::FFI.rpmtsSetRootDir(@ts, dir)
      raise "Can't set #{dir} as root directory" if rc < 0
    end

    # @returns [String ] the root directory for this transaction
    def root_dir
      RPM::FFI.rpmtsRootDir(@ts)
    end

    def flags=(fl)
      RPM::FFI.rpmtsSetFlags(@ts, fl)
    end

    def flags
      RPM::FFI.rpmtsFlags(@ts)
    end

    # Performs the transaction.
    # @param [Number] flag Transaction flags, default +RPM::TRANS_FLAG_NONE+
    # @param [Number] filter Transaction filter, default +RPM::PROB_FILTER_NONE+
    # @example
    #   transaction.commit do |sig|
    # end
    # @yield [CallbackData] sig Transaction progress
    def commit
      flags = RPM::FFI::TransFlags[:none]

      rc = RPM::FFI.rpmtsRun(@ts, nil, :none)
<commit_msg>fix doc<commit_after>require 'rpm'

module RPM

  class Transaction

    def self.release(ptr)
      RPM::FFI.rpmtsFree(ptr)
    end

    def initialize
      @ts = ::FFI::AutoPointer.new(RPM::FFI.rpmtsCreate, Transaction.method(:release))
      RPM::FFI.rpmtsSetRootDir(@ts, "/")
    end

    def ptr
      @ts
    end
    
    def each
      it = RPM::FFI.rpmtsInitIterator(@ts, 0, nil, 0)
      #STDERR.puts it.class
      while (not (header = RPM::FFI.rpmdbNextIterator(it)).null?)
        yield Header.new(header)
      end
      RPM::FFI.rpmdbFreeIterator(it)
    end

    # Add a install operation to the transaction
    # @param [Package] pkg Package to install
    def install(pkg, key)
      raise TypeError if not pkg.is_a?(RPM::Package)
      
      @keys ||= Array.new
      raise ArgError, "key must be unique" if @keys.include?(key)
      @keys << key
      
      RPM::FFI.rpmtsAddInstallElement(@ts, pkg.ptr, key.to_s, 0, nil)
      nil
    end

    # Sets the root directory for this transaction
    # @param [String] root directory
    def root_dir=(dir)
      rc = RPM::FFI.rpmtsSetRootDir(@ts, dir)
      raise "Can't set #{dir} as root directory" if rc < 0
    end

    # @return [String ] the root directory for this transaction
    def root_dir
      RPM::FFI.rpmtsRootDir(@ts)
    end

    def flags=(fl)
      RPM::FFI.rpmtsSetFlags(@ts, fl)
    end

    def flags
      RPM::FFI.rpmtsFlags(@ts)
    end

    # Performs the transaction.
    # @param [Number] flag Transaction flags, default +RPM::TRANS_FLAG_NONE+
    # @param [Number] filter Transaction filter, default +RPM::PROB_FILTER_NONE+
    # @example
    #   transaction.commit do |sig|
    # end
    # @yield [CallbackData] sig Transaction progress
    def commit
      flags = RPM::FFI::TransFlags[:none]

      rc = RPM::FFI.rpmtsRun(@ts, nil, :none)

{'fraction_non_alphanumeric': 0.11614654002713704, 'fraction_numerical': 0.002170963364993216, 'mean_word_length': 2.599609375, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4501855', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1235, 'n_words': 325}