~chipaca/ubuntu-push/fix-1383867--trunk

« back to all changes in this revision

Viewing changes to click/click.go

  • Committer: CI bot
  • Date: 2014-08-04 15:38:23 UTC
  • mfrom: (116.1.4 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140804153823-djffeana18j78bx1
* Add click hook to collect helpers data on install/update/etc and
  support to read the helper cached data, when available, and only
  refresh it when it changes.
* Include notification settings cleanup in the click install hook, and
  rename it to click-hook
* For the gsettings interface: Improve, add tests, make design-compliant.
* Query gsettings as to whether a notification should be presented.
* Cleanup and improve post/Post tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        "encoding/json"
23
23
        "errors"
24
24
        "fmt"
25
 
        "io/ioutil"
26
25
        "path/filepath"
27
26
        "regexp"
28
27
        "strings"
43
42
        original    string
44
43
}
45
44
 
46
 
var hookPath = filepath.Join(xdg.Data.Home(), "ubuntu-push-client", "helpers")
47
 
var hookExt = ".json"
48
 
 
49
45
// from https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId
50
46
// except the version is made optional
51
47
var rxClick = regexp.MustCompile(`^([a-z0-9][a-z0-9+.-]+)_([a-zA-Z0-9+.-]+)(?:_([0-9][a-zA-Z0-9.+:~-]*))?$`)
121
117
        }
122
118
}
123
119
 
124
 
type hookFile struct {
125
 
        AppId string `json:"app_id"`
126
 
        Exec  string `json:"exec"`
127
 
}
128
 
 
129
 
// Helper figures out the app id and executable of the untrusted
130
 
// helper for this app.
131
 
func (app *AppId) Helper() (helperAppId string, helperExec string) {
132
 
        if !app.Click {
133
 
                return "", ""
134
 
        }
135
 
        // xxx: should probably have a cache of this
136
 
        matches, err := filepath.Glob(filepath.Join(hookPath, app.Package+"_*"+hookExt))
137
 
        if err != nil {
138
 
                return "", ""
139
 
        }
140
 
        var v hookFile
141
 
        for _, m := range matches {
142
 
                abs, err := filepath.EvalSymlinks(m)
143
 
                if err != nil {
144
 
                        continue
145
 
                }
146
 
                data, err := ioutil.ReadFile(abs)
147
 
                if err != nil {
148
 
                        continue
149
 
                }
150
 
                err = json.Unmarshal(data, &v)
151
 
                if err != nil {
152
 
                        continue
153
 
                }
154
 
                if v.Exec != "" && (v.AppId == "" || v.AppId == app.Base()) {
155
 
                        basename := filepath.Base(m)
156
 
                        helperAppId = basename[:len(basename)-len(hookExt)]
157
 
                        helperExec = filepath.Join(filepath.Dir(abs), v.Exec)
158
 
                        return helperAppId, helperExec
159
 
                }
160
 
        }
161
 
        return "", ""
162
 
}
163
 
 
164
120
func (app *AppId) Versioned() string {
165
121
        if app.Click {
166
122
                if app.Version == "" {