<commit_before>package sloth

import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"time"
)

// for mock in this package
var timeNow = time.Now

// Make sure Logger always implements io.Writer
var _ io.WriteCloser = (*File)(nil)

// Logger writes specific to Filename
type File struct {
	Filename string
	Every    time.Duration

	file      *os.File
	createdAt time.Time
}

func (f *File) Write(b []byte) (n int, err error) {
	if f.file == nil {
		f.file, err = openNew(f.Filename, false)
		f.createdAt = timeNow()
	}

	if now := timeNow(); f.Every > 0 && now.Sub(f.createdAt) >= f.Every {
		backup(f)
	}
	return f.file.Write(b)
}

func (f *File) Close() error {
	return f.file.Close()
}

func backup(f *File) {
	name := f.file.Name()
	f.Close()

	backupfile, err := openNew(name, true)
	if err != nil {
		return
	}
	defer backupfile.Close()

	f.file, _ = openNew(name, false)
	f.createdAt = timeNow()
	if _, err := io.Copy(backupfile, f.file); err != nil {
		panic(err)
	}
}

func exist(filename string) bool {
	_, err := os.Stat(filename)
	return !os.IsNotExist(err)
}

func openNew(filename string, stamptime bool) (*os.File, error) {<commit_msg>Create method Name to return file name<commit_after>package sloth

import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"time"
)

// for mock in this package
var timeNow = time.Now

// Make sure Logger always implements io.Writer
var _ io.WriteCloser = (*File)(nil)

// Logger writes specific to Filename
type File struct {
	Filename string
	Every    time.Duration

	file      *os.File
	createdAt time.Time
}

func (f *File) Write(b []byte) (n int, err error) {
	if f.file == nil {
		f.file, err = openNew(f.Filename, false)
		f.createdAt = timeNow()
	}

	if now := timeNow(); f.Every > 0 && now.Sub(f.createdAt) >= f.Every {
		backup(f)
	}
	return f.file.Write(b)
}

func (f *File) Close() error {
	return f.file.Close()
}

func (f *File) Name() string { return f.file.Name() }

func backup(f *File) {
	name := f.Name()
	f.Close()

	backupfile, err := openNew(name, true)
	if err != nil {
		return
	}
	defer backupfile.Close()

	f.file, _ = openNew(name, false)
	f.createdAt = timeNow()
	if _, err := io.Copy(backupfile, f.file); err != nil {
		panic(err)
	}
}

func exist(filename string) bool {
	_, err := os.Stat(filename)
	return !os.IsNotExist(err)
}

func openNew(filename string, stamptime bool) (*os.File, error) {
{'fraction_non_alphanumeric': 0.1535850657615613, 'fraction_numerical': 0.0008485362749257531, 'mean_word_length': 3.4323308270676693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2025618', 'n_tokens_mistral': 921, 'n_tokens_neox': 900, 'n_words': 251}