(fileOp fileUtils.FileOp, index uint, dir string, rootTree *dto.CleanTree, excludes []string)
| 547 | } |
| 548 | |
| 549 | func loadFileOrDirWithExclude(fileOp fileUtils.FileOp, index uint, dir string, rootTree *dto.CleanTree, excludes []string) error { |
| 550 | index++ |
| 551 | entries, err := os.ReadDir(dir) |
| 552 | if err != nil { |
| 553 | return err |
| 554 | } |
| 555 | for _, entry := range entries { |
| 556 | childPath := filepath.Join(dir, entry.Name()) |
| 557 | if isExactPathMatch(childPath, excludes) { |
| 558 | continue |
| 559 | } |
| 560 | childNode := dto.CleanTree{ |
| 561 | ID: uuid.NewString(), |
| 562 | Label: entry.Name(), |
| 563 | IsCheck: false, |
| 564 | IsRecommend: false, |
| 565 | CanDelete: true, |
| 566 | Name: childPath, |
| 567 | Type: "unknown_backup", |
| 568 | } |
| 569 | if entry.IsDir() { |
| 570 | if index < 4 { |
| 571 | if err = loadFileOrDirWithExclude(fileOp, index, childPath, &childNode, excludes); err != nil { |
| 572 | return err |
| 573 | } |
| 574 | childNode.Size = 0 |
| 575 | for _, child := range childNode.Children { |
| 576 | childNode.Size += child.Size |
| 577 | } |
| 578 | } else { |
| 579 | itemSize, _ := fileOp.GetDirSize(childPath) |
| 580 | childNode.Size = uint64(itemSize) |
| 581 | } |
| 582 | if childNode.Size == 0 { |
| 583 | continue |
| 584 | } |
| 585 | } else { |
| 586 | info, _ := entry.Info() |
| 587 | childNode.Size = uint64(info.Size()) |
| 588 | } |
| 589 | |
| 590 | rootTree.Size += childNode.Size |
| 591 | rootTree.Children = append(rootTree.Children, childNode) |
| 592 | } |
| 593 | return nil |
| 594 | } |
| 595 | |
| 596 | func isExactPathMatch(path string, excludePaths []string) bool { |
| 597 | cleanPath := filepath.Clean(path) |
no test coverage detected