Skip to content

Commit

Permalink
quick hot fix androidbinary panic bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 17, 2017
1 parent 28e9a2c commit 6b3f0f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
30 changes: 21 additions & 9 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ type FileJSONInfo struct {
Extra interface{} `json:"extra,omitempty"`
}

// path should be absolute
func parseApkInfo(path string) (ai *ApkInfo) {
defer func() {
if err := recover(); err != nil {
log.Println("parse-apk-info panic:", err)
}
}()
apkf, err := apk.OpenFile(path)
if err != nil {
return
}
ai = &ApkInfo{}
ai.MainActivity, _ = apkf.MainAcitivty()
ai.PackageName = apkf.PackageName()
ai.Version.Code = apkf.Manifest().VersionCode
ai.Version.Name = apkf.Manifest().VersionName
return
}

func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) {
path := mux.Vars(r)["path"]
relPath := filepath.Join(s.Root, path)
Expand All @@ -205,15 +224,7 @@ func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) {
fji.Type = "markdown"
case ".apk":
fji.Type = "apk"
apkf, err := apk.OpenFile(relPath)
if err == nil {
ai := ApkInfo{}
ai.MainActivity, _ = apkf.MainAcitivty()
ai.PackageName = apkf.PackageName()
ai.Version.Code = apkf.Manifest().VersionCode
ai.Version.Name = apkf.Manifest().VersionName
fji.Extra = ai
}
fji.Extra = parseApkInfo(relPath)
default:
fji.Type = "text"
}
Expand Down Expand Up @@ -563,6 +574,7 @@ func (s *HTTPStaticServer) findIndex(text string) []IndexFileItem {
func (s *HTTPStaticServer) defaultAccessConf() AccessConf {
return AccessConf{
Upload: s.Upload,
Delete: s.Delete,
}
}

Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Configure struct {
Theme string `yaml:"theme"`
XHeaders bool `yaml:"xheaders"`
Upload bool `yaml:"upload"`
Delete bool `yaml:"delete"`
PlistProxy string `yaml:"plistproxy"`
Title string `yaml:"title"`
Debug bool `yaml:"debug"`
Expand Down Expand Up @@ -103,6 +104,7 @@ func parseFlags() error {
kingpin.Flag("auth-openid", "OpenID auth identity url").StringVar(&gcfg.Auth.OpenID)
kingpin.Flag("theme", "web theme, one of <black|green>").StringVar(&gcfg.Theme)
kingpin.Flag("upload", "enable upload support").BoolVar(&gcfg.Upload)
kingpin.Flag("delete", "enable delete support").BoolVar(&gcfg.Delete)
kingpin.Flag("xheaders", "used when behide nginx").BoolVar(&gcfg.XHeaders)
kingpin.Flag("cors", "enable cross-site HTTP request").BoolVar(&gcfg.Cors)
kingpin.Flag("debug", "enable debug mode").BoolVar(&gcfg.Debug)
Expand Down Expand Up @@ -140,6 +142,7 @@ func main() {
ss.Title = gcfg.Title
ss.GoogleTrackerId = gcfg.GoogleTrackerId
ss.Upload = gcfg.Upload
ss.Delete = gcfg.Delete
ss.AuthType = gcfg.Auth.Type

if gcfg.PlistProxy != "" {
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/shogo82148/androidbinary/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b3f0f0

Please sign in to comment.