MCPcopy
hub / github.com/chrislusf/glow / listOldLogFiles

Method listOldLogFiles

netchan/store/rotating_file_store.go:345–374  ·  view source on GitHub ↗

oldLogFiles returns the list of backup log files stored in the same directory as the current log file, sorted by ModTime

()

Source from the content-addressed store, hash-verified

343// oldLogFiles returns the list of backup log files stored in the same
344// directory as the current log file, sorted by ModTime
345func (l *RotatingFileStore) listOldLogFiles() ([]logInfo, error) {
346 os.MkdirAll(l.dir(), 0755)
347 files, err := ioutil.ReadDir(l.dir())
348 if err != nil {
349 return nil, fmt.Errorf("can't read log file directory: %s", err)
350 }
351 logFiles := []logInfo{}
352
353 prefix, ext := l.prefixAndExt()
354
355 for _, f := range files {
356 if f.IsDir() {
357 continue
358 }
359 name := l.timeFromName(f.Name(), prefix, ext)
360 if name == "" {
361 continue
362 }
363 t, err := time.Parse(backupTimeFormat, name)
364 if err == nil {
365 logFiles = append(logFiles, logInfo{t, f})
366 }
367 // error parsing means that the suffix at the end was not generated
368 // by lumberjack, and therefore it's not a backup file.
369 }
370
371 sort.Sort(byFormatTime(logFiles))
372
373 return logFiles, nil
374}
375
376// timeFromName extracts the formatted time from the filename by stripping off
377// the filename's prefix and extension. This prevents someone's filename from

Callers 1

cleanupMethod · 0.95

Calls 6

dirMethod · 0.95
prefixAndExtMethod · 0.95
timeFromNameMethod · 0.95
byFormatTimeTypeAlias · 0.85
SortMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected