<commit_before>package repofile

import (
	"fmt"
	"os"
	"os/user"
	"path"
	"path/filepath"
	"runtime"

	"github.com/arteev/logger"
)

//RepositoryFile - current file of repository
var (
	repositoryFile = "repository.sqlite"
	isDefaultRepo  = true
)

func init() {
	searchLocation()
}

func searchLocation() {
	//workdir
	if _, err := os.Stat(repositoryFile); err == nil {
		return
	}
	var cfgLocation string
	//appdata | ~/.config
	if u, err := user.Current(); err == nil {
		if runtime.GOOS == "windows" {
			cfgLocation = filepath.Join(u.HomeDir, os.Getenv("APPDATA"), "dsql", repositoryFile)
		} else {
			cfgLocation = filepath.Join(u.HomeDir, ".config", "dsql", repositoryFile)
		}
		if _, err := os.Stat(cfgLocation); err == nil {
			repositoryFile = cfgLocation
            return
		}
        
	}
	//folder dsql
	absPath, _ := filepath.Abs(path.Dir(os.Args[0]))
	inAppLocation := path.Join(absPath, repositoryFile)
	if _, err := os.Stat(inAppLocation); err == nil {
		repositoryFile = inAppLocation
		return
	}
	if cfgLocation != "" {
		repositoryFile = cfgLocation
	}
}

//SetRepositoryFile - set new location repository file
func SetRepositoryFile(filename string) {
	if !isDefaultRepo {
		panic(fmt.Errorf("can't twice change repository file "))
	}
	if filename != "" {
		isDefaultRepo = false
		repositoryFile = filename
	}
}

//GetRepositoryFile - get current location repository file
func GetRepositoryFile() string {
	return repositoryFile
}

//IsDefault returns location repository file is default
func IsDefault() bool {
	return isDefaultRepo
}

//PrepareLocation - make directories for repository files
func PrepareLocation() {
	dir := path.Dir(repositoryFile)
	if dir == "" {
		return
	}
	perm := 0700
	if err := os.MkdirAll(dir, os.FileMode(perm)); err != nil {
		logger.Error.Println(err)
	}
}
<commit_msg>repo file: fix appdata<commit_after>package repofile

import (
	"fmt"
	"os"
	"os/user"
	"path"
	"path/filepath"
	"runtime"

	"github.com/arteev/logger"
    
)

//RepositoryFile - current file of repository
var (
	repositoryFile = "repository.sqlite"
	isDefaultRepo  = true
)

func init() {
	searchLocation()
}

func searchLocation() {
	//workdir
	if _, err := os.Stat(repositoryFile); err == nil {
		return
	}
	var cfgLocation string
	//appdata | ~/.config
	if u, err := user.Current(); err == nil {
		if runtime.GOOS == "windows" {
			cfgLocation = filepath.Join(u.HomeDir, os.Getenv("APPDATA"), "dsql", repositoryFile)
		} else {
			cfgLocation = filepath.Join(u.HomeDir, ".config", "dsql", repositoryFile)
		}
		if _, err := os.Stat(cfgLocation); err == nil {
			repositoryFile = cfgLocation
            return
		}
        
	}
	//folder dsql
	absPath, _ := filepath.Abs(path.Dir(os.Args[0]))
	inAppLocation := path.Join(absPath, repositoryFile)
	if _, err := os.Stat(inAppLocation); err == nil {
		repositoryFile = inAppLocation
		return
	}
	if cfgLocation != "" {
		repositoryFile = cfgLocation
	}
}

//SetRepositoryFile - set new location repository file
func SetRepositoryFile(filename string) {
	if !isDefaultRepo {
		panic(fmt.Errorf("can't twice change repository file "))
	}
	if filename != "" {
		isDefaultRepo = false
		repositoryFile = filename
	}
}

//GetRepositoryFile - get current location repository file
func GetRepositoryFile() string {
	return repositoryFile
}

//IsDefault returns location repository file is default
func IsDefault() bool {
	return isDefaultRepo
}

//PrepareLocation - make directories for repository files
func PrepareLocation() {
	dir := filepath.Dir(repositoryFile)    
    if dir == "" || dir == "." {
		return
	}    
	perm := 0700
    
	if err := os.MkdirAll(dir, os.FileMode(perm)); err != nil {
		logger.Error.Println(err)
	}
}

{'fraction_non_alphanumeric': 0.13135135135135134, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 3.6612090680100757, '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': '2717296', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1228, 'n_words': 306}