gitlab.com/evatix-go/core@v1.3.55/chmodhelper/GetExistsFilteredPathFileInfoMap.go (about)

     1  package chmodhelper
     2  
     3  import (
     4  	"os"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  	"gitlab.com/evatix-go/core/errcore"
     8  	"gitlab.com/evatix-go/core/internal/fsinternal"
     9  )
    10  
    11  func GetExistsFilteredPathFileInfoMap(
    12  	isSkipOnInvalid bool,
    13  	locations ...string,
    14  ) *FilteredPathFileInfoMap {
    15  	if len(locations) == 0 {
    16  		return InvalidFilteredPathFileInfoMap()
    17  	}
    18  
    19  	results := make(
    20  		map[string]os.FileInfo,
    21  		len(locations)+constants.Capacity4)
    22  
    23  	var missingOrHaveIssuesFiles []string
    24  
    25  	for _, location := range locations {
    26  		info, isExist, _ :=
    27  			fsinternal.GetPathExistStat(location)
    28  
    29  		if isExist && info != nil {
    30  			results[location] = info
    31  		} else {
    32  			missingOrHaveIssuesFiles = append(
    33  				missingOrHaveIssuesFiles,
    34  				location)
    35  		}
    36  	}
    37  
    38  	var err2 error
    39  	if len(missingOrHaveIssuesFiles) > 0 && !isSkipOnInvalid {
    40  		err2 = errcore.PathsMissingOrHavingIssuesType.ErrorRefOnly(
    41  			missingOrHaveIssuesFiles)
    42  	}
    43  
    44  	return &FilteredPathFileInfoMap{
    45  		FilesToInfoMap:           results,
    46  		MissingOrOtherPathIssues: missingOrHaveIssuesFiles,
    47  		Error:                    err2,
    48  	}
    49  }