1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 20:20:55 +00:00

unzip to swagger while not swagger-2

This commit is contained in:
astaxie 2016-08-19 23:45:18 +08:00
parent 8bda698fce
commit b5bf9d07c3
2 changed files with 6 additions and 8 deletions

View File

@ -650,7 +650,7 @@ func checkEnv(appname string) (apppath, packpath string, err error) {
for _, gpath := range gps { for _, gpath := range gps {
gsrcpath := path.Join(gpath, "src") gsrcpath := path.Join(gpath, "src")
if strings.HasPrefix(currpath, gsrcpath) { if strings.HasPrefix(currpath, gsrcpath) {
return currpath, currpath[len(gsrcpath):], nil return currpath, currpath[len(gsrcpath)+1:], nil
} }
} }

View File

@ -20,6 +20,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strings"
) )
var cmdRundocs = &Command{ var cmdRundocs = &Command{
@ -120,6 +121,7 @@ func unzipAndDelete(src string) error {
} }
defer r.Close() defer r.Close()
rp := strings.NewReplacer("swagger-"+swaggerVersion, "swagger")
for _, f := range r.File { for _, f := range r.File {
rc, err := f.Open() rc, err := f.Open()
if err != nil { if err != nil {
@ -127,11 +129,12 @@ func unzipAndDelete(src string) error {
} }
defer rc.Close() defer rc.Close()
fname := rp.Replace(f.Name)
if f.FileInfo().IsDir() { if f.FileInfo().IsDir() {
os.MkdirAll(f.Name, f.Mode()) os.MkdirAll(fname, f.Mode())
} else { } else {
f, err := os.OpenFile( f, err := os.OpenFile(
f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) fname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil { if err != nil {
return err return err
} }
@ -143,11 +146,6 @@ func unzipAndDelete(src string) error {
} }
} }
} }
os.RemoveAll("swagger")
err = os.Rename("swagger-"+swaggerVersion, "swagger")
if err != nil {
ColorLog("[%s]Rename swagger-%s to swagger:%s\n", ERRO, swaggerVersion, err)
}
ColorLog("[%s]Start delete src file %s\n", INFO, src) ColorLog("[%s]Start delete src file %s\n", INFO, src)
return os.RemoveAll(src) return os.RemoveAll(src)
} }