<commit_before>package dargo

import (
	"archive/tar"
	"bytes"
	"io/ioutil"
	"os"
)

// makeTar builds a tar ready to upload to a Docker engine including a
// Dockerfile and a copy of the running binary
func makeTar() (*bytes.Reader, error) {
	// Create a buffer to write our archive to.
	buf := new(bytes.Buffer)

	// Create a new tar archive.
	tw := tar.NewWriter(buf)

	self, err := ioutil.ReadFile(os.Args[0])
	if err != nil {
		return nil, err
	}
	Dockerfile := "FROM scratch\r\nADD app /app\r\nENTRYPOINT [\"/app\"]"

	if err := tw.WriteHeader(&tar.Header{
		Name: "Dockerfile",
		Mode: 0600,
		Size: int64(len(Dockerfile)),
	}); err != nil {
		return nil, err
	}
	if _, err := tw.Write([]byte(Dockerfile)); err != nil {
		return nil, err
	}
	if err := tw.WriteHeader(&tar.Header{
		Name: "app",
		Mode: 0755,
		Size: int64(len(self)),<commit_msg>Detect static binary or not<commit_after>package dargo

import (
	"archive/tar"
	"bytes"
	"debug/elf"
	"fmt"
	"io/ioutil"
	"os"
)

func readMe() ([]byte, error) {
	self, err := ioutil.ReadFile(os.Args[0])
	if err != nil {
		return nil, err
	}

	e, err := elf.NewFile(bytes.NewReader(self))
	if err != nil {
		return nil, err
	}

	_, err = e.DynamicSymbols()
	if err == nil || err.Error() != "no symbol section" {
		return nil, fmt.Errorf("Not a static binary")
	}

	return self, nil
}

// makeTar builds a tar ready to upload to a Docker engine including a
// Dockerfile and a copy of the running binary
func makeTar() (*bytes.Reader, error) {
	// Create a buffer to write our archive to.
	buf := new(bytes.Buffer)

	// Create a new tar archive.
	tw := tar.NewWriter(buf)

	self, err := readMe()
	if err != nil {
		return nil, err
	}
	Dockerfile := "FROM scratch\r\nADD app /app\r\nENTRYPOINT [\"/app\"]"

	if err := tw.WriteHeader(&tar.Header{
		Name: "Dockerfile",
		Mode: 0600,
		Size: int64(len(Dockerfile)),
	}); err != nil {
		return nil, err
	}
	if _, err := tw.Write([]byte(Dockerfile)); err != nil {
		return nil, err
	}
	if err := tw.WriteHeader(&tar.Header{
		Name: "app",
		Mode: 0755,
		Size: int64(len(self)),
{'fraction_non_alphanumeric': 0.16040462427745664, 'fraction_numerical': 0.012524084778420038, 'mean_word_length': 3.4004237288135593, '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': '4568868', 'n_tokens_mistral': 834, 'n_tokens_neox': 780, 'n_words': 235}