<commit_before>package influxdb

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
)

const (
	nodeFile      = "node.json"
	oldNodeFile   = "id"
	peersFilename = "peers.json"
)

type Node struct {
	path        string
	ID          uint64
	MetaServers []string
}

// LoadNode will load the node information from disk if present
func LoadNode(path string, addrs []string) (*Node, error) {
	// Always check to see if we are upgrading first
	if err := upgradeNodeFile(path, addrs); err != nil {
		return nil, err
	}

	n := &Node{
		path: path,
	}

	f, err := os.Open(filepath.Join(path, nodeFile))
	if err != nil {
		return nil, err
	}
	defer f.Close()

	if err := json.NewDecoder(f).Decode(n); err != nil {
		return nil, err
	}

	return n, nil
}

// NewNode will return a new node
func NewNode(path string, addrs []string) *Node {
	return &Node{
		path:        path,
		MetaServers: addrs,
	}
}

// Save will save the node file to disk and replace the existing one if present
func (n *Node) Save() error {
	file := filepath.Join(n.path, nodeFile)
	tmpFile := file + "tmp"

	f, err := os.Create(tmpFile)
	if err != nil {
		return err
	}
	defer f.Close()

	if err := json.NewEncoder(f).Encode(n); err != nil {
		return err
	}

	return os.Rename(tmpFile, file)
}

// AddMetaServers adds the addrs to the set of MetaServers known to this node.
// If an addr already exists, it will not be re-added.
func (n *Node) AddMetaServers(addrs []string) {
	unique := map[string]struct{}{}
	for _, addr := range n.MetaServers {
		unique[addr] = struct{}{}
	}

	for _, addr := range addrs {
		unique[addr] = struct{}{}
	}

	metaServers := []string{}
	for addr := range unique {
		metaServers = append(metaServers, addr)<commit_msg>fix rename file fail on the windows<commit_after>package influxdb

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
)

const (
	nodeFile      = "node.json"
	oldNodeFile   = "id"
	peersFilename = "peers.json"
)

type Node struct {
	path        string
	ID          uint64
	MetaServers []string
}

// LoadNode will load the node information from disk if present
func LoadNode(path string, addrs []string) (*Node, error) {
	// Always check to see if we are upgrading first
	if err := upgradeNodeFile(path, addrs); err != nil {
		return nil, err
	}

	n := &Node{
		path: path,
	}

	f, err := os.Open(filepath.Join(path, nodeFile))
	if err != nil {
		return nil, err
	}
	defer f.Close()

	if err := json.NewDecoder(f).Decode(n); err != nil {
		return nil, err
	}

	return n, nil
}

// NewNode will return a new node
func NewNode(path string, addrs []string) *Node {
	return &Node{
		path:        path,
		MetaServers: addrs,
	}
}

// Save will save the node file to disk and replace the existing one if present
func (n *Node) Save() error {
	file := filepath.Join(n.path, nodeFile)
	tmpFile := file + "tmp"

	f, err := os.Create(tmpFile)
	if err != nil {
		return err
	}

	if err = json.NewEncoder(f).Encode(n); err != nil {
		f.Close()
		return err
	}

	if err = f.Close(); nil != err {
		return err
	}

	return os.Rename(tmpFile, file)
}

// AddMetaServers adds the addrs to the set of MetaServers known to this node.
// If an addr already exists, it will not be re-added.
func (n *Node) AddMetaServers(addrs []string) {
	unique := map[string]struct{}{}
	for _, addr := range n.MetaServers {
		unique[addr] = struct{}{}
	}

	for _, addr := range addrs {
		unique[addr] = struct{}{}
	}

	metaServers := []string{}
	for addr := range unique {
		metaServers = append(metaServers, addr)
{'fraction_non_alphanumeric': 0.13355874894336434, 'fraction_numerical': 0.0011270780501549732, 'mean_word_length': 3.236276849642005, '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': '2777472', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1268, 'n_words': 415}