diff --git a/tools/goctl/util/zipx/zipx.go b/tools/goctl/util/zipx/zipx.go index 2b1619dd..0071150d 100644 --- a/tools/goctl/util/zipx/zipx.go +++ b/tools/goctl/util/zipx/zipx.go @@ -16,10 +16,15 @@ func Unpacking(name, destPath string, mapper func(f *zip.File) bool) error { } defer r.Close() + destAbsPath, err := filepath.Abs(destPath) + if err != nil { + return err + } + for _, file := range r.File { ok := mapper(file) if ok { - err = fileCopy(file, destPath) + err = fileCopy(file, destAbsPath) if err != nil { return err } @@ -34,7 +39,12 @@ func fileCopy(file *zip.File, destPath string) error { return err } defer rc.Close() - filename := filepath.Join(destPath, filepath.Base(file.Name)) + abs, err := filepath.Abs(file.Name) + if err != nil { + return err + } + + filename := filepath.Join(destPath, filepath.Base(abs)) dir := filepath.Dir(filename) err = pathx.MkdirIfNotExist(dir) if err != nil {