Fix MaybeRel when OUT is absolute
MaybeRel was failing with an error when comparing an absolute out path to a relative source path. Make it return false instead, and add tests. Bug: 119412419 Test: paths_test.go Change-Id: I462182638bd57b1367b5bfb0718e975c11ae66f7
This commit is contained in:
@@ -1054,6 +1054,10 @@ func Rel(ctx PathContext, basePath string, targetPath string) string {
|
||||
// MaybeRel performs the same function as filepath.Rel, but reports errors to a PathContext, and returns false if
|
||||
// targetPath is not inside basePath.
|
||||
func MaybeRel(ctx PathContext, basePath string, targetPath string) (string, bool) {
|
||||
// filepath.Rel returns an error if one path is absolute and the other is not, handle that case first.
|
||||
if filepath.IsAbs(basePath) != filepath.IsAbs(targetPath) {
|
||||
return "", false
|
||||
}
|
||||
rel, err := filepath.Rel(basePath, targetPath)
|
||||
if err != nil {
|
||||
reportPathError(ctx, err)
|
||||
|
Reference in New Issue
Block a user