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

     1  package chmodhelper
     2  
     3  // MergeRwxWildcardWithFixedRwx
     4  //
     5  //  - existingRwx : Usually refers to fixed rwx values like "rwx", "--x", "-w-" etc.
     6  //  - rwxWildcardInput : Usually refers to fixed rwx values like "rw*", "*-x", "-w-" etc.
     7  //      Wildcard means keep the existing value as is.
     8  //
     9  //  Example:
    10  //   - existingRwx        : (rwx : "r-x"),
    11  //   - rwxWildcardInput   : (rwx : "r*-")
    12  //   - @returns           : "r--"
    13  func MergeRwxWildcardWithFixedRwx(
    14  	existingRwx,
    15  	rwxWildcardInput string,
    16  ) (
    17  	fixedAttribute *Attribute,
    18  	err error,
    19  ) {
    20  	length := len(rwxWildcardInput)
    21  
    22  	if length != SingleRwxLength {
    23  		return nil, GetRwxLengthError(rwxWildcardInput)
    24  	}
    25  
    26  	length2 := len(existingRwx)
    27  
    28  	if length2 != SingleRwxLength {
    29  		return nil, GetRwxLengthError(existingRwx)
    30  	}
    31  
    32  	varAttr, err := ParseRwxToVarAttribute(rwxWildcardInput)
    33  
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	attr := New.Attribute.UsingRwxString(existingRwx)
    39  	fixedAttr := varAttr.ToCompileAttr(&attr)
    40  
    41  	return &fixedAttr, nil
    42  }