<commit_before>function download_elixir() {
  fix_elixir_version

  # If a previous download does not exist, then always re-download
  if [ ${force_fetch} = true ] || [ ! -f ${cache_path}/$(elixir_download_file) ]; then
    clean_elixir_downloads
    elixir_changed=true
    local otp_version=$(otp_version ${erlang_version})

    local download_url="https://repo.hex.pm/builds/elixir/${elixir_version}-otp-${otp_version}.zip"

    output_section "Fetching Elixir ${elixir_version} for OTP ${otp_version} from ${download_url}"

    curl -s ${download_url} -o ${cache_path}/$(elixir_download_file)

    if [ $? -ne 0 ]; then
      output_section "Falling back to fetching Elixir ${elixir_version} for generic OTP version"
      local download_url="https://repo.hex.pm/builds/elixir/${elixir_version}.zip"
      curl -s ${download_url} -o ${cache_path}/$(elixir_download_file) || exit 1
    fi
  else
    output_section "Using cached Elixir ${elixir_version}"
  fi
}

function install_elixir() {
  output_section "Installing Elixir ${elixir_version} $(elixir_changed)"

  mkdir -p $(elixir_path)
  cd $(elixir_path)

  if type "unzip" &> /dev/null; then
    unzip -q ${cache_path}/$(elixir_download_file)
  else
    jar xf ${cache_path}/$(elixir_download_file)
  fi

  cd - > /dev/null

  chmod +x $(elixir_path)/bin/*
  PATH=$(elixir_path)/bin:${PATH}

  export LC_CTYPE=en_US.utf8
}

function fix_elixir_version() {
  if [ ${#elixir_version[@]} -eq 2 ] && [ ${elixir_version[0]} = "branch" ]; then
    force_fetch=true
    elixir_version=${elixir_version[1]}

  elif [ ${#elixir_version[@]} -eq 1 ]; then
    force_fetch=false

    # If we detect a version string (e.g. 1.14 or 1.14.0) we prefix it with "v"
    if [[ ${elixir_version} =~ ^[0-9]+\.[0-9]+ ]]; then
      elixir_version=v${elixir_version}
    fi

  else
    output_line "Invalid Elixir version specified"
    output_line "See the README for allowed formats at:"
    output_line "https://github.com/HashNuke/heroku-buildpack-elixir"
    exit 1
  fi
}

function elixir_download_file() {
  echo elixir-${elixir_version}.zip
}

function clean_elixir_downloads() {
  rm -rf ${cache_path}/elixir*.zip
}

function restore_mix() {
  if [ -d $(mix_backup_path) ]; then
    mkdir -p ${HOME}/.mix
    cp -pR $(mix_backup_path)/* ${HOME}/.mix
  fi

  if [ -d $(hex_backup_path) ]; then
    mkdir -p ${HOME}/.hex
    cp -pR $(hex_backup_path)/* ${HOME}/.hex
  fi<commit_msg>strip out non-digit non-dot characters on version string, for example ^M, which many customers have run into.<commit_after>function download_elixir() {
  fix_elixir_version

  # If a previous download does not exist, then always re-download
  if [ ${force_fetch} = true ] || [ ! -f ${cache_path}/$(elixir_download_file) ]; then
    clean_elixir_downloads
    elixir_changed=true
    local otp_version=$(otp_version ${erlang_version})

    local download_url="https://repo.hex.pm/builds/elixir/${elixir_version}-otp-${otp_version}.zip"

    output_section "Fetching Elixir ${elixir_version} for OTP ${otp_version} from ${download_url}"

    curl -s ${download_url} -o ${cache_path}/$(elixir_download_file)

    if [ $? -ne 0 ]; then
      output_section "Falling back to fetching Elixir ${elixir_version} for generic OTP version"
      local download_url="https://repo.hex.pm/builds/elixir/${elixir_version}.zip"
      curl -s ${download_url} -o ${cache_path}/$(elixir_download_file) || exit 1
    fi
  else
    output_section "Using cached Elixir ${elixir_version}"
  fi
}

function install_elixir() {
  output_section "Installing Elixir ${elixir_version} $(elixir_changed)"

  mkdir -p $(elixir_path)
  cd $(elixir_path)

  if type "unzip" &> /dev/null; then
    unzip -q ${cache_path}/$(elixir_download_file)
  else
    jar xf ${cache_path}/$(elixir_download_file)
  fi

  cd - > /dev/null

  chmod +x $(elixir_path)/bin/*
  PATH=$(elixir_path)/bin:${PATH}

  export LC_CTYPE=en_US.utf8
}

function fix_elixir_version() {
  if [ ${#elixir_version[@]} -eq 2 ] && [ ${elixir_version[0]} = "branch" ]; then
    force_fetch=true
    elixir_version=${elixir_version[1]}

  elif [ ${#elixir_version[@]} -eq 1 ]; then
    force_fetch=false

    # If we detect a version string (e.g. 1.14 or 1.14.0) we prefix it with "v"
    if [[ ${elixir_version} =~ ^[0-9]+\.[0-9]+ ]]; then
      # strip out any non-digit non-dot characters
      # TODO: what about ^M for non-version strings?
      elixir_version=$(echo "$elixir_version" | sed 's/[^0-9.]*//g')
      elixir_version=v${elixir_version}
    fi

  else
    output_line "Invalid Elixir version specified"
    output_line "See the README for allowed formats at:"
    output_line "https://github.com/HashNuke/heroku-buildpack-elixir"
    exit 1
  fi
}

function elixir_download_file() {
  echo elixir-${elixir_version}.zip
}

function clean_elixir_downloads() {
  rm -rf ${cache_path}/elixir*.zip
}

function restore_mix() {
  if [ -d $(mix_backup_path) ]; then
    mkdir -p ${HOME}/.mix
    cp -pR $(mix_backup_path)/* ${HOME}/.mix
  fi

  if [ -d $(hex_backup_path) ]; then
    mkdir -p ${HOME}/.hex
    cp -pR $(hex_backup_path)/* ${HOME}/.hex
  fi
{'fraction_non_alphanumeric': 0.14547939855496972, 'fraction_numerical': 0.007810974419058777, 'mean_word_length': 3.707720588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '765897', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1901, 'n_words': 426}