getLogFiles returns all the log files in the directory sorted by the first index in each file.
(dir string)
| 251 | // getLogFiles returns all the log files in the directory sorted by the first |
| 252 | // index in each file. |
| 253 | func getLogFiles(dir string) ([]*logFile, error) { |
| 254 | entryFiles := x.WalkPathFunc(dir, func(path string, isDir bool) bool { |
| 255 | if isDir { |
| 256 | return false |
| 257 | } |
| 258 | if strings.HasSuffix(path, logSuffix) { |
| 259 | return true |
| 260 | } |
| 261 | return false |
| 262 | }) |
| 263 | |
| 264 | var files []*logFile |
| 265 | seen := make(map[int64]struct{}) |
| 266 | |
| 267 | for _, fpath := range entryFiles { |
| 268 | _, fname := filepath.Split(fpath) |
| 269 | fname = strings.TrimSuffix(fname, logSuffix) |
| 270 | |
| 271 | fid, err := strconv.ParseInt(fname, 10, 64) |
| 272 | if err != nil { |
| 273 | return nil, errors.Wrapf(err, "while parsing: %s", fpath) |
| 274 | } |
| 275 | |
| 276 | if _, ok := seen[fid]; ok { |
| 277 | glog.Fatalf("Entry file with id: %d is repeated", fid) |
| 278 | } |
| 279 | seen[fid] = struct{}{} |
| 280 | |
| 281 | f, err := openLogFile(dir, fid) |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | glog.Infof("Found file: %d First Index: %d\n", fid, f.firstIndex()) |
| 286 | files = append(files, f) |
| 287 | } |
| 288 | |
| 289 | // Sort files by the first index they store. |
| 290 | sort.Slice(files, func(i, j int) bool { |
| 291 | return files[i].getEntry(0).Index() < files[j].getEntry(0).Index() |
| 292 | }) |
| 293 | return files, nil |
| 294 | } |
| 295 | |
| 296 | // KeyID returns datakey's ID. |
| 297 | func (lf *logFile) keyID() uint64 { |
searching dependent graphs…