<commit_before>package platform

import (
	"io/ioutil"
	"os"
	"path"
	"regexp"
	"strings"
)

type linuxInfoFunc func(string) (string, string, string, error)

var linuxInfoFuncs = map[string]linuxInfoFunc{
	"arch":   linuxInfoArch,
	"debian": linuxInfoDebian,
	"fedora": linuxInfoFedora,
	"ubuntu": linuxInfoUbuntu,
}

func linuxInfoArch(etc string) (string, string, string, error) {
	return "arch", "", "", nil
}

func linuxInfoDebian(etc string) (string, string, string, error) {
	data, err := ioutil.ReadFile(path.Join(etc, "debian_version"))
	if err != nil {
		return "", "", "", err
	}

	return "debian", strings.TrimSpace(string(data)), "", nil
}

func linuxInfoFedora(etc string) (string, string, string, error) {
	data, err := ioutil.ReadFile(path.Join(etc, "fedora-release"))
	if err != nil {
		return "", "", "", err
	}
	re, _ := regexp.Compile(`Fedora release (.*) \((.*)\)`)
	result := re.FindAllStringSubmatch(string(data), -1)

	return "fedora", result[0][1], result[0][2], nil
}

func linuxInfoUbuntu(etc string) (string, string, string, error) {
	lsb, err := ReadLsbReleaseFile(path.Join(etc, "lsb-release"))
	if err != nil {
		return "", "", "", err
	}

	return "ubuntu", lsb.Release, lsb.Codename, nil
}

func LinuxDistribution(args ...string) (string, string, string, error) {
	root := "/"

	if len(args) >= 1 {
		root = args[0]
	}

	etc := path.Join(root, "etc")
	osReleasePath := path.Join(etc, "os-release")

	if _, err := os.Stat(osReleasePath); err == nil {
		orf, err := ReadOsReleaseFile(osReleasePath)
		if err != nil {
			return "", "", "", err
		}

		if _, ok := linuxInfoFuncs[orf.ID]; ok {
			return linuxInfoFuncs[orf.ID](etc)
		}
	}

	return "unknown", "", "", nil
}<commit_msg>Add comment for LinuxDistribution()<commit_after>package platform

import (
	"io/ioutil"
	"os"
	"path"
	"regexp"
	"strings"
)

type linuxInfoFunc func(string) (string, string, string, error)

var linuxInfoFuncs = map[string]linuxInfoFunc{
	"arch":   linuxInfoArch,
	"debian": linuxInfoDebian,
	"fedora": linuxInfoFedora,
	"ubuntu": linuxInfoUbuntu,
}

func linuxInfoArch(etc string) (string, string, string, error) {
	return "arch", "", "", nil
}

func linuxInfoDebian(etc string) (string, string, string, error) {
	data, err := ioutil.ReadFile(path.Join(etc, "debian_version"))
	if err != nil {
		return "", "", "", err
	}

	return "debian", strings.TrimSpace(string(data)), "", nil
}

func linuxInfoFedora(etc string) (string, string, string, error) {
	data, err := ioutil.ReadFile(path.Join(etc, "fedora-release"))
	if err != nil {
		return "", "", "", err
	}
	re, _ := regexp.Compile(`Fedora release (.*) \((.*)\)`)
	result := re.FindAllStringSubmatch(string(data), -1)

	return "fedora", result[0][1], result[0][2], nil
}

func linuxInfoUbuntu(etc string) (string, string, string, error) {
	lsb, err := ReadLsbReleaseFile(path.Join(etc, "lsb-release"))
	if err != nil {
		return "", "", "", err
	}

	return "ubuntu", lsb.Release, lsb.Codename, nil
}

// LinuxDistribution tries to determine linux distribution info
// Returns distname, version, id, err
//
// supported distributions are: Arch, Fedora, Debian, Ubuntu
// for any other distribution or non-linux system,
// LinuxDistribution() will return ("uknown", "", "", nil)
func LinuxDistribution(args ...string) (string, string, string, error) {
	root := "/"

	if len(args) >= 1 {
		root = args[0]
	}

	etc := path.Join(root, "etc")
	osReleasePath := path.Join(etc, "os-release")

	if _, err := os.Stat(osReleasePath); err == nil {
		orf, err := ReadOsReleaseFile(osReleasePath)
		if err != nil {
			return "", "", "", err
		}

		if _, ok := linuxInfoFuncs[orf.ID]; ok {
			return linuxInfoFuncs[orf.ID](etc)
		}
	}

	return "unknown", "", "", nil
}
{'fraction_non_alphanumeric': 0.18235610543302852, 'fraction_numerical': 0.0037654653039268424, 'mean_word_length': 4.421282798833819, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, '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': '2778861', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1307, 'n_words': 324}