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

     1  package chmodhelper
     2  
     3  import (
     4  	"io/fs"
     5  	"path/filepath"
     6  
     7  	"gitlab.com/evatix-go/core/constants"
     8  	"gitlab.com/evatix-go/core/errcore"
     9  )
    10  
    11  func GetRecursivePaths(
    12  	isContinueOnError bool,
    13  	rootPath string,
    14  ) ([]string, error) {
    15  	stat := GetPathExistStat(rootPath)
    16  
    17  	if !stat.IsExist {
    18  		return []string{}, errcore.PathsMissingOrHavingIssuesType.
    19  			ErrorRefOnly(rootPath)
    20  	}
    21  
    22  	if stat.IsFile() {
    23  		return []string{rootPath}, nil
    24  	}
    25  
    26  	if isContinueOnError {
    27  		return GetRecursivePathsContinueOnError(rootPath)
    28  	}
    29  
    30  	allPaths := make(
    31  		[]string,
    32  		0,
    33  		constants.Capacity128)
    34  	var sliceErr []string
    35  
    36  	finalErr := filepath.Walk(
    37  		rootPath,
    38  		func(path string, info fs.FileInfo, err error) error {
    39  			if err != nil {
    40  				sliceErr = append(
    41  					sliceErr,
    42  					err.Error()+constants.HyphenAngelRight+path)
    43  
    44  				return err
    45  			}
    46  
    47  			allPaths = append(allPaths, path)
    48  
    49  			return nil
    50  		})
    51  
    52  	if finalErr != nil {
    53  		sliceErr = append(
    54  			sliceErr,
    55  			finalErr.Error()+constants.HyphenAngelRight+rootPath)
    56  	}
    57  
    58  	return allPaths, errcore.SliceToError(sliceErr)
    59  }