23d20c9db5
If a packager wants to be able to support addititional arguments on his hook this will allow them to setup the configuration with these arguments. For example this would allow a hook developer to add support for a --debug flag to change the level of debugging in his hook. In order to complete this task, I had to vendor in the latest github.com://opencontainers/runtime-tools, which caused me to have to fix a Mount and Capability interface calls Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
32 lines
714 B
Go
32 lines
714 B
Go
package filepath
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// IsAncestor returns true when pathB is an strict ancestor of pathA,
|
|
// and false where the paths are equal or pathB is outside of pathA.
|
|
// Paths that are not absolute will be made absolute with Abs.
|
|
func IsAncestor(os, pathA, pathB, cwd string) (_ bool, err error) {
|
|
if pathA == pathB {
|
|
return false, nil
|
|
}
|
|
|
|
pathA, err = Abs(os, pathA, cwd)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
pathB, err = Abs(os, pathB, cwd)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
sep := Separator(os)
|
|
if !strings.HasSuffix(pathA, string(sep)) {
|
|
pathA = fmt.Sprintf("%s%c", pathA, sep)
|
|
}
|
|
if pathA == pathB {
|
|
return false, nil
|
|
}
|
|
return strings.HasPrefix(pathB, pathA), nil
|
|
}
|