oldLogFiles returns the list of backup log files stored in the same directory as the current log file, sorted by ModTime
()
| 343 | // oldLogFiles returns the list of backup log files stored in the same |
| 344 | // directory as the current log file, sorted by ModTime |
| 345 | func (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 |
no test coverage detected