feat:
1. local msg/file share by webrtc fix: 1. meta clean goroutine walk error 2. clean interval to args(--clean)
This commit is contained in:
@ -135,14 +135,25 @@ func (m *meta) Start(ctx context.Context) {
|
||||
|
||||
// 清理一天前的文件
|
||||
go func() {
|
||||
if opt.Cfg.CleanInterval <= 0 {
|
||||
log.Warn("meta.Clean: no clean interval set, plz clean manual!!!")
|
||||
return
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(5 * time.Minute)
|
||||
duration := time.Duration(opt.Cfg.CleanInterval) * time.Hour
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case now := <-ticker.C:
|
||||
//log.Debug("meta.Clean: 开始清理过期文件 = %v", duration)
|
||||
_ = filepath.Walk(opt.Cfg.DataPath, func(path string, info os.FileInfo, err error) error {
|
||||
if info == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
@ -168,12 +179,16 @@ func (m *meta) Start(ctx context.Context) {
|
||||
|
||||
code := strings.TrimPrefix(name, ".meta.")
|
||||
|
||||
if now.Sub(time.UnixMilli(mi.CreatedAt)) > 24*time.Hour {
|
||||
if now.Sub(time.UnixMilli(mi.CreatedAt)) > duration {
|
||||
|
||||
log.Debug("controller.meta: file out of date, code = %s, user_key = %s", code, mi.Uploader)
|
||||
|
||||
os.RemoveAll(opt.FilePath(code))
|
||||
os.RemoveAll(path)
|
||||
if err = os.RemoveAll(opt.FilePath(code)); err != nil {
|
||||
log.Warn("meta.Clean: remove file failed, file = %s, err = %s", opt.FilePath(code), err.Error())
|
||||
}
|
||||
if err = os.RemoveAll(path); err != nil {
|
||||
log.Warn("meta.Clean: remove file failed, file = %s, err = %s", path, err.Error())
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
delete(m.m, code)
|
||||
|
Reference in New Issue
Block a user