From 648e0747f61077c8df8972765761a26e90ef8073 Mon Sep 17 00:00:00 2001 From: Yves Baldus Date: Wed, 19 Jun 2024 11:23:17 +0200 Subject: [PATCH] fix: fix the directory for cleaning files --- rotatefile/writer.go | 2 +- rotatefile/writer_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rotatefile/writer.go b/rotatefile/writer.go index fec9d0a..f065f42 100644 --- a/rotatefile/writer.go +++ b/rotatefile/writer.go @@ -317,7 +317,7 @@ func (d *Writer) Clean() (err error) { fileDir, fileName := path.Split(d.cfg.Filepath) // find and clean old files - err = fsutil.FindInDir(fileDir[:len(fileDir)-2], func(fPath string, ent fs.DirEntry) error { + err = fsutil.FindInDir(fileDir[:len(fileDir)-1], func(fPath string, ent fs.DirEntry) error { fi, err := ent.Info() if err != nil { return err diff --git a/rotatefile/writer_test.go b/rotatefile/writer_test.go index f3b178b..0aa8594 100644 --- a/rotatefile/writer_test.go +++ b/rotatefile/writer_test.go @@ -128,6 +128,9 @@ func TestWriter_Clean(t *testing.T) { c.Compress = true err = wr.Clean() assert.NoErr(t, err) + + files := fsutil.Glob(logfile + ".*") + assert.Equal(t, 2, len(files)) }) }