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

     1  package chmodhelper
     2  
     3  import (
     4  	"os"
     5  )
     6  
     7  // IsChmod expectedHyphenedRwx should be 10 chars example "-rwxrwxrwx"
     8  func IsChmod(location string, expectedHyphenedRwx string) bool {
     9  	if len(expectedHyphenedRwx) != HyphenedRwxLength {
    10  		return false
    11  	}
    12  
    13  	if location == "" {
    14  		return false
    15  	}
    16  
    17  	fileInfo, err := os.Stat(location)
    18  
    19  	if os.IsNotExist(err) || fileInfo == nil {
    20  		return false
    21  	}
    22  
    23  	existingFileMode := fileInfo.Mode().String()[1:]
    24  
    25  	return existingFileMode == expectedHyphenedRwx[1:]
    26  }