github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/misc/android/cleaner.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Cleaner removes anything from /data/local/tmp/goroot not on a builtin list. 6 // Used by androidtest.bash. 7 package main 8 9 import ( 10 "log" 11 "os" 12 "path/filepath" 13 "strings" 14 ) 15 16 func main() { 17 const goroot = "/data/local/tmp/goroot" 18 expect := make(map[string]bool) 19 for _, f := range strings.Split(files, "\n") { 20 expect[filepath.Join(goroot, f)] = true 21 } 22 23 err := filepath.Walk(goroot, func(path string, info os.FileInfo, err error) error { 24 if expect[path] { 25 return nil 26 } 27 log.Printf("removing %s", path) 28 if err := os.RemoveAll(path); err != nil { 29 return err 30 } 31 if info.IsDir() { 32 return filepath.SkipDir 33 } 34 return nil 35 }) 36 if err != nil { 37 log.Fatal(err) 38 } 39 }