Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
fix: stock on startup
Browse files Browse the repository at this point in the history
Change-Id: Id539dbd2fb7c1493d89c6edb04340fe1cef3c52c
  • Loading branch information
Iceyer committed Jan 3, 2019
1 parent 208aedd commit 42601fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
if err != nil {
logger.Fatal(err)
}
m.updateCache()
go m.updateCache()

// caller := service.Conn().Object("com.deepin.pusher", "/com/deepin/pusher")
// err = caller.Call("com.deepin.pusher.Register", 0, "store", dbusServiceName, dbusMetadataPath, dbusMetadataInterface).Store()
Expand Down
7 changes: 6 additions & 1 deletion src/daemon/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"sync"
"time"

"github.com/go-ini/ini"
Expand All @@ -20,7 +21,8 @@ type Metadata struct {
block *blocklist
debBackend *Backend

apps map[string]*AppBody
mutex sync.Mutex
apps map[string]*AppBody

methods *struct {
GetAppIcon func() `in:"appName" out:"path"`
Expand Down Expand Up @@ -179,6 +181,9 @@ func (m *Metadata) getAppIcon(appName string) string {
}

func (m *Metadata) updateCache() {
m.mutex.Lock()
defer m.mutex.Unlock()

if len(m.apps) > 0 {
return
}
Expand Down
17 changes: 12 additions & 5 deletions src/daemon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ func cacheFetchJSON(v interface{}, url, cacheFilepath string, expire time.Durati
}
defer resp.Body.Close()

gzipReader, err := gzip.NewReader(resp.Body)
if err != nil {
logger.Error("gzip data read failed: %v", err)
return err
var reader io.ReadCloser
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, err = gzip.NewReader(resp.Body)
if err != nil {
logger.Errorf("gzip data read %q failed: %v", url, err)
return err
}
defer reader.Close()
default:
reader = resp.Body
}

jsonDec := json.NewDecoder(gzipReader)
jsonDec := json.NewDecoder(reader)
err = jsonDec.Decode(v)
if err != nil {
logger.Error("json decode failed: %v", err)
Expand Down

0 comments on commit 42601fc

Please sign in to comment.