Go over all saved artifacts and update the name list to make sure all the files & folders are reflected in the final report. Hopefully, just a temporary workaround until a proper refactoring.
()
| 2669 | // sure all the files & folders are reflected in the final report. |
| 2670 | // Hopefully, just a temporary workaround until a proper refactoring. |
| 2671 | func (p *store) enumerateArtifacts() { |
| 2672 | logger := log.WithField("op", "store.enumerateArtifacts") |
| 2673 | logger.Trace("call") |
| 2674 | defer logger.Trace("exit") |
| 2675 | |
| 2676 | knownFiles := list2map(p.nameList) |
| 2677 | artifactFilesDir := filepath.Join(p.storeLocation, app.ArtifactFilesDirName) |
| 2678 | |
| 2679 | var curpath string |
| 2680 | dirqueue := []string{artifactFilesDir} |
| 2681 | for len(dirqueue) > 0 { |
| 2682 | curpath, dirqueue = dirqueue[0], dirqueue[1:] |
| 2683 | |
| 2684 | entries, err := os.ReadDir(curpath) |
| 2685 | if err != nil { |
| 2686 | logger.WithError(err).Debugf("os.ReadDir(%s)", curpath) |
| 2687 | // Keep processing though since it might have been a partial result. |
| 2688 | } |
| 2689 | |
| 2690 | // Leaf element - empty dir. |
| 2691 | if len(entries) == 0 { |
| 2692 | // Trim /opt/_slim/artifacts/files prefix from the dirpath. |
| 2693 | curpath = strings.TrimPrefix(curpath, artifactFilesDir) |
| 2694 | |
| 2695 | if knownFiles[curpath] { |
| 2696 | continue |
| 2697 | } |
| 2698 | |
| 2699 | if props, err := artifactProps(curpath); err == nil { |
| 2700 | p.nameList = append(p.nameList, curpath) |
| 2701 | p.rawNames[curpath] = props |
| 2702 | knownFiles[curpath] = true |
| 2703 | } else { |
| 2704 | logger.WithError(err). |
| 2705 | WithField("path", curpath). |
| 2706 | Debugf("artifactProps(%s): failed computing dir artifact props", curpath) |
| 2707 | } |
| 2708 | continue |
| 2709 | } |
| 2710 | |
| 2711 | for _, child := range entries { |
| 2712 | childpath := filepath.Join(curpath, child.Name()) |
| 2713 | if child.IsDir() { |
| 2714 | dirqueue = append(dirqueue, childpath) |
| 2715 | continue |
| 2716 | } |
| 2717 | |
| 2718 | // Trim /opt/_slim/artifacts/files prefix from the filepath. |
| 2719 | childpath = strings.TrimPrefix(childpath, artifactFilesDir) |
| 2720 | |
| 2721 | // Leaf element - regular file or symlink. |
| 2722 | if knownFiles[childpath] { |
| 2723 | continue |
| 2724 | } |
| 2725 | |
| 2726 | if props, err := artifactProps(childpath); err == nil { |
| 2727 | p.nameList = append(p.nameList, childpath) |
| 2728 | p.rawNames[childpath] = props |
no test coverage detected