<commit_before>require 'archive/tar/minitar'
require 'json'
require 'zlib'

module VagrantMutate
  class Box

    include Archive::Tar

    attr_reader :dir, :name, :provider

    def initialize( env )
      @env = env
    end

    def prepare_for_output( name, provider )
      @name = name
      @provider = provider
      @dir = create_output_dir()
      @dir_is_tmp = false
    end

    def load_from_file(file)
      @name = file[0..-5]
      @dir = unpack(file)
      @dir_is_tmp = true
      @provider = determine_provider()
    end

    def load_by_name(name)
      @name = name
      # cheat for now since only supported input is virtualbox
      @provider = 'virtualbox'
      @dir = find_input_dir()
      @dir_is_tmp = false
    end

    def cleanup
      if @dir_is_tmp
        FileUtils.remove_entry_secure(@dir)
      end
    end

    def determine_provider
      begin
        metadata = JSON.load( File.new( File.join(@dir, 'metadata.json'), 'r') )
      rescue => e
        raise Errors::DetermineProviderFailed, :error_message => e.message
      end
      return metadata['provider']
    end

    def find_input_dir
      in_dir = File.join( @env['boxes_path'], @name, 'virtualbox' )
      if File.directory?(in_dir)
        return in_dir
      else
        raise Errors::BoxNotFound, :box => in_dir
      end
    end

    def create_output_dir
      # e.g. $HOME/.vagrant.d/boxes/fedora-19/libvirt
      out_dir = File.join( @env['boxes_path'], @name, @provider )
      begin
        Dir.mkdir(out_dir)
      rescue => e
        raise Errors::CreateBoxDirFailed, :error_message => e.message
      end<commit_msg>Fix box path and directory creation<commit_after>require 'archive/tar/minitar'
require 'fileutils'
require 'json'
require 'zlib'

module VagrantMutate
  class Box

    include Archive::Tar

    attr_reader :dir, :name, :provider

    def initialize( env )
      @env = env
    end

    def prepare_for_output( name, provider )
      @name = name
      @provider = provider
      @dir = create_output_dir()
      @dir_is_tmp = false
    end

    def load_from_file(file)
      @name = file[0..-5]
      @dir = unpack(file)
      @dir_is_tmp = true
      @provider = determine_provider()
    end

    def load_by_name(name)
      @name = name
      # cheat for now since only supported input is virtualbox
      @provider = 'virtualbox'
      @dir = find_input_dir()
      @dir_is_tmp = false
    end

    def cleanup
      if @dir_is_tmp
        FileUtils.remove_entry_secure(@dir)
      end
    end

    def determine_provider
      begin
        metadata = JSON.load( File.new( File.join(@dir, 'metadata.json'), 'r') )
      rescue => e
        raise Errors::DetermineProviderFailed, :error_message => e.message
      end
      return metadata['provider']
    end

    def find_input_dir
      in_dir = File.join( @env.boxes_path, @name, 'virtualbox' )
      if File.directory?(in_dir)
        return in_dir
      else
        raise Errors::BoxNotFound, :box => in_dir
      end
    end

    def create_output_dir
      # e.g. $HOME/.vagrant.d/boxes/fedora-19/libvirt
      out_dir = File.join( @env.boxes_path, @name, @provider )
      begin
        FileUtils.mkdir_p(out_dir)
      rescue => e
        raise Errors::CreateBoxDirFailed, :error_message => e.message
      end
{'fraction_non_alphanumeric': 0.09854897218863362, 'fraction_numerical': 0.0024183796856106408, 'mean_word_length': 2.3356854838709675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1520141', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1052, 'n_words': 262}