|
|
@@ -20,14 +20,16 @@ import (
|
|
|
"sort"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "go.uber.org/zap"
|
|
|
)
|
|
|
|
|
|
-func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error {
|
|
|
- return purgeFile(dirname, suffix, max, interval, stop, nil)
|
|
|
+func PurgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error {
|
|
|
+ return purgeFile(lg, dirname, suffix, max, interval, stop, nil)
|
|
|
}
|
|
|
|
|
|
// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil.
|
|
|
-func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error {
|
|
|
+func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error {
|
|
|
errC := make(chan error, 1)
|
|
|
go func() {
|
|
|
for {
|
|
|
@@ -55,11 +57,19 @@ func purgeFile(dirname string, suffix string, max uint, interval time.Duration,
|
|
|
return
|
|
|
}
|
|
|
if err = l.Close(); err != nil {
|
|
|
- plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err)
|
|
|
+ if lg != nil {
|
|
|
+ lg.Warn("failed to unlock/close", zap.String("path", l.Name()), zap.Error(err))
|
|
|
+ } else {
|
|
|
+ plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err)
|
|
|
+ }
|
|
|
errC <- err
|
|
|
return
|
|
|
}
|
|
|
- plog.Infof("purged file %s successfully", f)
|
|
|
+ if lg != nil {
|
|
|
+ lg.Info("purged", zap.String("path", f))
|
|
|
+ } else {
|
|
|
+ plog.Infof("purged file %s successfully", f)
|
|
|
+ }
|
|
|
newfnames = newfnames[1:]
|
|
|
}
|
|
|
if purgec != nil {
|