Support RuleBuilder.Sbox to wrap commands in sbox
This essentially allows you to declare that everything in a directory will be created by the rule, and we'll ensure that your command actually writes out all of the claimed outputs, and remove any other files that previously existed in that directory. Test: built-in tests Change-Id: I990dce2b3a0d89ebd2736ac1a0cadfb5864c6e73
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user