github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/cmd/runner/cleanup.go (about) 1 package runner 2 3 import ( 4 "go/build" 5 "io/ioutil" 6 "os" 7 "path" 8 "strings" 9 ) 10 11 func cleanSharedLibs(lgopath string, sessID *SessionID) error { 12 pkg := path.Join(lgopath, "pkg") 13 files, err := ioutil.ReadDir(pkg) 14 if err != nil { 15 return err 16 } 17 prefix := "libgithub.com-yunabe-lgo-" + sessID.Marshal() 18 for _, f := range files { 19 if strings.HasPrefix(f.Name(), prefix) && strings.HasSuffix(f.Name(), ".so") { 20 if rerr := os.Remove(path.Join(pkg, f.Name())); rerr != nil && err == nil { 21 err = rerr 22 } 23 } 24 } 25 if rerr := os.RemoveAll(path.Join(pkg, "github.com/yunabe/lgo", sessID.Marshal())); rerr != nil { 26 err = rerr 27 } 28 return err 29 } 30 31 // CleanSession cleans up files for a session specified by sessNum. 32 // CleanSession returns nil when no target file exists. 33 func CleanSession(lgopath string, sessID *SessionID) error { 34 srcErr := os.RemoveAll(path.Join(build.Default.GOPATH, "src/github.com/yunabe/lgo", sessID.Marshal())) 35 soErr := cleanSharedLibs(lgopath, sessID) 36 if srcErr != nil { 37 return srcErr 38 } 39 return soErr 40 }