aboutsummaryrefslogtreecommitdiffstats
path: root/android/paths.go
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-11-27 02:27:10 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-11-27 02:27:10 +0000
commit9d7a8975d9eae1fe22788707c41a67e6e3ce92c7 (patch)
treea2eccd26193e970726af5fd4e6799b79a571855a /android/paths.go
parent36bd23552aee4fb119aff13d2d4a20b293660a2d (diff)
parentd9c1c8fbcb242d2aacebbd9dc28702b402fe44f4 (diff)
downloadbuild_soong-9d7a8975d9eae1fe22788707c41a67e6e3ce92c7.tar.gz
build_soong-9d7a8975d9eae1fe22788707c41a67e6e3ce92c7.tar.bz2
build_soong-9d7a8975d9eae1fe22788707c41a67e6e3ce92c7.zip
Snap for 6034952 from d9c1c8fbcb242d2aacebbd9dc28702b402fe44f4 to qt-qpr2-release
Change-Id: If50010e646664876b1e50fa9a4a49a766a60e94f
Diffstat (limited to 'android/paths.go')
-rw-r--r--android/paths.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/android/paths.go b/android/paths.go
index 8cc7057a..0f20b844 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1267,16 +1267,23 @@ 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) {
+ rel, isRel, err := maybeRelErr(basePath, targetPath)
+ if err != nil {
+ reportPathError(ctx, err)
+ }
+ return rel, isRel
+}
+
+func maybeRelErr(basePath string, targetPath string) (string, bool, error) {
// 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
+ return "", false, nil
}
rel, err := filepath.Rel(basePath, targetPath)
if err != nil {
- reportPathError(ctx, err)
- return "", false
+ return "", false, err
} else if rel == ".." || strings.HasPrefix(rel, "../") || strings.HasPrefix(rel, "/") {
- return "", false
+ return "", false, nil
}
- return rel, true
+ return rel, true, nil
}