<commit_before>package migration

import (
	"io/ioutil"
	"path/filepath"
	"strings"

	"github.com/pufferpanel/pufferd/logging"
	"encoding/json"
	"github.com/pufferpanel/pufferd/utils"
	"os"
	"github.com/pufferpanel/pufferd/programs"
	"github.com/pufferpanel/pufferd/data/templates"
)

const Scales = "/srv/scales/data"

func MigrateFromScales() {
	templates.CopyTemplates()
	os.MkdirAll(programs.ServerFolder, 0755)

	programFiles, err := ioutil.ReadDir(Scales)
	if err != nil {
		logging.Critical("Error reading from old Scales folder", err)
		return
	}
	for _, element := range programFiles {
		if element.IsDir() {
			continue
		}
		id := strings.TrimSuffix(element.Name(), filepath.Ext(element.Name()))
		logging.Infof("Attempting to migrate %s", id)
		data, err := ioutil.ReadFile(utils.JoinPath(Scales, element.Name()))
		if err != nil {
			logging.Error("Error read server config", err)
			continue
		}
		scales := scalesServer{}
		err = json.Unmarshal(data, &scales)
		if err != nil {
			logging.Error("Error read server config", err)
			continue
		}
		newPath := utils.JoinPath("data", "servers", scales.Name)
		err = os.Rename(utils.JoinPath("/home", scales.User), newPath)
		if err != nil {
			logging.Error("Error moving folder", err);
			continue
		}

		err = filepath.Walk(newPath, func(name string, info os.FileInfo, err error) {
			if err == nil {
				err = os.Chown(name, os.Getuid(), os.Getgid())
			}
			return err
		})
		if err != nil {
			logging.Error("Error changing owner of folder", err);
			continue
		}
		serverData := make(map[string]interface{})<commit_msg>Fix compilation issue<commit_after>package migration

import (
	"io/ioutil"
	"path/filepath"
	"strings"

	"github.com/pufferpanel/pufferd/logging"
	"encoding/json"
	"github.com/pufferpanel/pufferd/utils"
	"os"
	"github.com/pufferpanel/pufferd/programs"
	"github.com/pufferpanel/pufferd/data/templates"
)

const Scales = "/srv/scales/data"

func MigrateFromScales() {
	templates.CopyTemplates()
	os.MkdirAll(programs.ServerFolder, 0755)

	programFiles, err := ioutil.ReadDir(Scales)
	if err != nil {
		logging.Critical("Error reading from old Scales folder", err)
		return
	}
	for _, element := range programFiles {
		if element.IsDir() {
			continue
		}
		id := strings.TrimSuffix(element.Name(), filepath.Ext(element.Name()))
		logging.Infof("Attempting to migrate %s", id)
		data, err := ioutil.ReadFile(utils.JoinPath(Scales, element.Name()))
		if err != nil {
			logging.Error("Error read server config", err)
			continue
		}
		scales := scalesServer{}
		err = json.Unmarshal(data, &scales)
		if err != nil {
			logging.Error("Error read server config", err)
			continue
		}
		newPath := utils.JoinPath("data", "servers", scales.Name)
		err = os.Rename(utils.JoinPath("/home", scales.User), newPath)
		if err != nil {
			logging.Error("Error moving folder", err);
			continue
		}

		err = filepath.Walk(newPath, func(name string, info os.FileInfo, err error) error {
			if err == nil {
				err = os.Chown(name, os.Getuid(), os.Getgid())
			}
			return err
		})
		if err != nil {
			logging.Error("Error changing owner of folder", err);
			continue
		}
		serverData := make(map[string]interface{})
{'fraction_non_alphanumeric': 0.14626490897677338, 'fraction_numerical': 0.0025109855618330196, 'mean_word_length': 3.9952978056426334, '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': '199913', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1107, 'n_words': 244}