Merge lp:~chipaca/snappy/reduce-manifest into lp:~snappy-dev/snappy/snappy-moved-to-github
- reduce-manifest
- Merge into snappy-moved-to-github
Proposed by
John Lenton
Status: | Merged |
---|---|
Approved by: | Michael Vogt |
Approved revision: | 466 |
Merged at revision: | 465 |
Proposed branch: | lp:~chipaca/snappy/reduce-manifest |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
657 lines (+104/-161) 16 files modified
pkg/types.go (+2/-0) pkg/types_test.go (+2/-0) snappy/build_test.go (+0/-2) snappy/click.go (+29/-42) snappy/click_test.go (+10/-10) snappy/config.go (+1/-1) snappy/datadir.go (+2/-2) snappy/datadir_test.go (+3/-3) snappy/install.go (+1/-1) snappy/install_test.go (+1/-0) snappy/parts.go (+2/-2) snappy/purge.go (+3/-3) snappy/snapp.go (+22/-6) snappy/snapp_test.go (+26/-0) snappy/udev.go (+0/-38) snappy/udev_test.go (+0/-51) |
To merge this branch: | bzr merge lp:~chipaca/snappy/reduce-manifest |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Vogt (community) | Approve | ||
Review via email: mp+259539@code.launchpad.net |
Commit message
Keep the use of clickManifest to a minimum (use packagYaml instead). Also misc cleanups.
Description of the change
This cuts down on usage of clickManifest, which is now only used from places that need to read or write to it directly. This means it can be an internal detail.
As a nice side effect, it's now painfully obvious which things should actually be methods on SnapPart: if it gets a packageYaml and a namespace, it should be using a SnapPart instead.
Also: random drive-by cleanups.
To post a comment you must log in.
- 465. By John Lenton
-
keep the use of clickManifest to a minimum (use packagYaml instead)
Revision history for this message
Michael Vogt (mvo) wrote : | # |
- 466. By John Lenton
-
qualifiedName, not dirname. Also renamed tests.
Revision history for this message
Michael Vogt (mvo) wrote : | # |
I like "qualifiedName"! Thanks a lot for this change!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'pkg/types.go' |
2 | --- pkg/types.go 2015-05-19 11:13:06 +0000 |
3 | +++ pkg/types.go 2015-05-20 09:49:44 +0000 |
4 | @@ -1,3 +1,5 @@ |
5 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
6 | + |
7 | /* |
8 | * Copyright (C) 2014-2015 Canonical Ltd |
9 | * |
10 | |
11 | === modified file 'pkg/types_test.go' |
12 | --- pkg/types_test.go 2015-05-19 11:13:06 +0000 |
13 | +++ pkg/types_test.go 2015-05-20 09:49:44 +0000 |
14 | @@ -1,3 +1,5 @@ |
15 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
16 | + |
17 | /* |
18 | * Copyright (C) 2014-2015 Canonical Ltd |
19 | * |
20 | |
21 | === modified file 'snappy/build_test.go' |
22 | --- snappy/build_test.go 2015-05-15 13:33:27 +0000 |
23 | +++ snappy/build_test.go 2015-05-20 09:49:44 +0000 |
24 | @@ -462,8 +462,6 @@ |
25 | readFiles, err := exec.Command("dpkg-deb", "-c", "hello_1.0.1_all.snap").CombinedOutput() |
26 | c.Assert(err, IsNil) |
27 | |
28 | - println(string(readFiles)) |
29 | - |
30 | // check that we really have the right perms |
31 | c.Assert(strings.Contains(string(readFiles), `drwxrwxrwx`), Equals, true) |
32 | c.Assert(strings.Contains(string(readFiles), `-rw-rw-rw-`), Equals, true) |
33 | |
34 | === modified file 'snappy/click.go' |
35 | --- snappy/click.go 2015-05-19 17:32:01 +0000 |
36 | +++ snappy/click.go 2015-05-20 09:49:44 +0000 |
37 | @@ -181,13 +181,13 @@ |
38 | |
39 | // iterHooks will run the callback "f" for the given manifest |
40 | // so that the call back can arrange e.g. a new link |
41 | -func iterHooks(manifest clickManifest, inhibitHooks bool, f iterHooksFunc) error { |
42 | +func iterHooks(m *packageYaml, namespace string, inhibitHooks bool, f iterHooksFunc) error { |
43 | systemHooks, err := systemClickHooks() |
44 | if err != nil { |
45 | return err |
46 | } |
47 | |
48 | - for app, hook := range manifest.Hooks { |
49 | + for app, hook := range m.Integration { |
50 | for hookName, hookSourceFile := range hook { |
51 | // ignore hooks that only exist for compatibility |
52 | // with the old snappy-python (like bin-path, |
53 | @@ -202,7 +202,7 @@ |
54 | continue |
55 | } |
56 | |
57 | - dst := filepath.Join(globalRootDir, expandHookPattern(manifest.Name, app, manifest.Version, systemHook.pattern)) |
58 | + dst := filepath.Join(globalRootDir, expandHookPattern(m.qualifiedName(namespace), app, m.Version, systemHook.pattern)) |
59 | |
60 | if _, err := os.Stat(dst); err == nil { |
61 | if err := os.Remove(dst); err != nil { |
62 | @@ -227,8 +227,8 @@ |
63 | return nil |
64 | } |
65 | |
66 | -func installClickHooks(targetDir string, manifest clickManifest, inhibitHooks bool) error { |
67 | - return iterHooks(manifest, inhibitHooks, func(src, dst string, systemHook clickHook) error { |
68 | +func installClickHooks(targetDir string, m *packageYaml, namespace string, inhibitHooks bool) error { |
69 | + return iterHooks(m, namespace, inhibitHooks, func(src, dst string, systemHook clickHook) error { |
70 | // setup the new link target here, iterHooks will take |
71 | // care of running the hook |
72 | realSrc := stripGlobalRootDir(path.Join(targetDir, src)) |
73 | @@ -240,8 +240,8 @@ |
74 | }) |
75 | } |
76 | |
77 | -func removeClickHooks(manifest clickManifest, inhibitHooks bool) (err error) { |
78 | - return iterHooks(manifest, inhibitHooks, func(src, dst string, systemHook clickHook) error { |
79 | +func removeClickHooks(m *packageYaml, namespace string, inhibitHooks bool) (err error) { |
80 | + return iterHooks(m, namespace, inhibitHooks, func(src, dst string, systemHook clickHook) error { |
81 | // nothing we need to do here, the iterHookss will remove |
82 | // the hook symlink and call the hook itself |
83 | return nil |
84 | @@ -262,12 +262,12 @@ |
85 | } |
86 | |
87 | func removeClick(clickDir string, inter interacter) (err error) { |
88 | - manifest, err := readClickManifestFromClickDir(clickDir) |
89 | + m, err := parsePackageYamlFile(filepath.Join(clickDir, "meta", "package.yaml")) |
90 | if err != nil { |
91 | return err |
92 | } |
93 | |
94 | - if err := removeClickHooks(manifest, false); err != nil { |
95 | + if err := removeClickHooks(m, namespaceFromBasedir(clickDir), false); err != nil { |
96 | return err |
97 | } |
98 | |
99 | @@ -367,17 +367,14 @@ |
100 | ` |
101 | |
102 | // it's fine for this to error out; we might be in a framework or sth |
103 | - namespace, _ := namespaceFromYamlPath(filepath.Join(pkgPath, "meta", "package.yaml")) |
104 | + namespace := namespaceFromBasedir(pkgPath) |
105 | |
106 | if err := verifyBinariesYaml(binary); err != nil { |
107 | return "", err |
108 | } |
109 | |
110 | actualBinPath := binPathForBinary(pkgPath, binary) |
111 | - udevPartName, err := getUdevPartName(m, pkgPath) |
112 | - if err != nil { |
113 | - return "", err |
114 | - } |
115 | + udevPartName := m.qualifiedName(namespace) |
116 | |
117 | var templateOut bytes.Buffer |
118 | t := template.Must(template.New("wrapper").Parse(wrapperTemplate)) |
119 | @@ -455,10 +452,7 @@ |
120 | return "", err |
121 | } |
122 | |
123 | - udevPartName, err := getUdevPartName(m, baseDir) |
124 | - if err != nil { |
125 | - return "", err |
126 | - } |
127 | + udevPartName := m.qualifiedName(namespaceFromBasedir(baseDir)) |
128 | |
129 | return systemd.New(globalRootDir, nil).GenServiceFile( |
130 | &systemd.ServiceDescription{ |
131 | @@ -835,11 +829,6 @@ |
132 | return "", err |
133 | } |
134 | |
135 | - manifest, err := readClickManifest([]byte(manifestData)) |
136 | - if err != nil { |
137 | - return "", err |
138 | - } |
139 | - |
140 | yamlData, err := d.MetaMember("package.yaml") |
141 | if err != nil { |
142 | return "", err |
143 | @@ -864,15 +853,14 @@ |
144 | |
145 | targetDir := snapAppsDir |
146 | // the "oem" parts are special |
147 | - if manifest.Type == pkg.TypeOem { |
148 | + if m.Type == pkg.TypeOem { |
149 | targetDir = snapOemDir |
150 | |
151 | // TODO do the following at a higher level once the store publishes snap types |
152 | // this is horrible |
153 | if allowOEM := (flags & AllowOEM) != 0; !allowOEM { |
154 | if currentOEM, err := getOem(); err == nil { |
155 | - if currentOEM.Name != manifest.Name { |
156 | - fmt.Println(currentOEM.Name, manifest.Name) |
157 | + if currentOEM.Name != m.Name { |
158 | return "", ErrOEMPackageInstall |
159 | } |
160 | } else { |
161 | @@ -886,19 +874,15 @@ |
162 | } |
163 | } |
164 | |
165 | - fullName := manifest.Name |
166 | - // namespacing only applies to apps. |
167 | - if manifest.Type != pkg.TypeFramework && manifest.Type != pkg.TypeOem { |
168 | - fullName += "." + namespace |
169 | - } |
170 | - instDir := filepath.Join(targetDir, fullName, manifest.Version) |
171 | + fullName := m.qualifiedName(namespace) |
172 | + instDir := filepath.Join(targetDir, fullName, m.Version) |
173 | currentActiveDir, _ := filepath.EvalSymlinks(filepath.Join(instDir, "..", "current")) |
174 | |
175 | if err := m.checkLicenseAgreement(inter, d, currentActiveDir); err != nil { |
176 | return "", err |
177 | } |
178 | |
179 | - dataDir := filepath.Join(snapDataDir, fullName, manifest.Version) |
180 | + dataDir := filepath.Join(snapDataDir, fullName, m.Version) |
181 | |
182 | if err := helpers.EnsureDir(instDir, 0755); err != nil { |
183 | logger.Noticef("Can not create %q: %v", instDir, err) |
184 | @@ -944,7 +928,7 @@ |
185 | // |
186 | // otherwise just create a empty data dir |
187 | if currentActiveDir != "" { |
188 | - oldManifest, err := readClickManifestFromClickDir(currentActiveDir) |
189 | + oldM, err := parsePackageYamlFile(filepath.Join(currentActiveDir, "meta", "package.yaml")) |
190 | if err != nil { |
191 | return "", err |
192 | } |
193 | @@ -962,15 +946,15 @@ |
194 | return "", err |
195 | } |
196 | |
197 | - err = copySnapData(fullName, oldManifest.Version, manifest.Version) |
198 | + err = copySnapData(fullName, oldM.Version, m.Version) |
199 | } else { |
200 | err = helpers.EnsureDir(dataDir, 0755) |
201 | } |
202 | |
203 | defer func() { |
204 | if err != nil { |
205 | - if cerr := removeSnapData(fullName, manifest.Version); cerr != nil { |
206 | - logger.Noticef("When cleaning up data for %s %s: %v", manifest.Name, manifest.Version, cerr) |
207 | + if cerr := removeSnapData(fullName, m.Version); cerr != nil { |
208 | + logger.Noticef("When cleaning up data for %s %s: %v", m.Name, m.Version, cerr) |
209 | } |
210 | } |
211 | }() |
212 | @@ -984,7 +968,7 @@ |
213 | defer func() { |
214 | if err != nil && currentActiveDir != "" { |
215 | if cerr := setActiveClick(currentActiveDir, inhibitHooks, inter); cerr != nil { |
216 | - logger.Noticef("When setting old %s version back to active: %v", manifest.Name, cerr) |
217 | + logger.Noticef("When setting old %s version back to active: %v", m.Name, cerr) |
218 | } |
219 | } |
220 | }() |
221 | @@ -1054,7 +1038,7 @@ |
222 | } |
223 | } |
224 | |
225 | - return manifest.Name, nil |
226 | + return m.Name, nil |
227 | } |
228 | |
229 | // removeSnapData removes the data for the given version of the given snap |
230 | @@ -1152,6 +1136,7 @@ |
231 | if err != nil { |
232 | return err |
233 | } |
234 | + |
235 | if err := m.removeSecurityPolicy(clickDir); err != nil { |
236 | return err |
237 | } |
238 | @@ -1168,7 +1153,7 @@ |
239 | } |
240 | } |
241 | |
242 | - if err := removeClickHooks(manifest, inhibitHooks); err != nil { |
243 | + if err := removeClickHooks(m, namespaceFromBasedir(clickDir), inhibitHooks); err != nil { |
244 | return err |
245 | } |
246 | |
247 | @@ -1207,15 +1192,17 @@ |
248 | return err |
249 | } |
250 | |
251 | + namespace := namespaceFromBasedir(baseDir) |
252 | + |
253 | if newActiveManifest.Type == pkg.TypeFramework { |
254 | if err := policy.Install(m.Name, baseDir); err != nil { |
255 | return err |
256 | } |
257 | } |
258 | |
259 | - if err := installClickHooks(baseDir, newActiveManifest, inhibitHooks); err != nil { |
260 | + if err := installClickHooks(baseDir, m, namespace, inhibitHooks); err != nil { |
261 | // cleanup the failed hooks |
262 | - removeClickHooks(newActiveManifest, inhibitHooks) |
263 | + removeClickHooks(m, namespace, inhibitHooks) |
264 | return err |
265 | } |
266 | |
267 | |
268 | === modified file 'snappy/click_test.go' |
269 | --- snappy/click_test.go 2015-05-19 17:32:01 +0000 |
270 | +++ snappy/click_test.go 2015-05-20 09:49:44 +0000 |
271 | @@ -141,26 +141,26 @@ |
272 | os.MkdirAll(instDir, 0755) |
273 | ioutil.WriteFile(path.Join(instDir, "path-to-systemd-file"), []byte(""), 0644) |
274 | ioutil.WriteFile(path.Join(instDir, "path-to-apparmor-file"), []byte(""), 0644) |
275 | - manifest := clickManifest{ |
276 | + m := &packageYaml{ |
277 | Name: "foo", |
278 | Version: "1.0", |
279 | - Hooks: map[string]clickAppHook{ |
280 | + Integration: map[string]clickAppHook{ |
281 | "app": clickAppHook{ |
282 | "systemd": "path-to-systemd-file", |
283 | "apparmor": "path-to-apparmor-file", |
284 | }, |
285 | }, |
286 | } |
287 | - err := installClickHooks(instDir, manifest, false) |
288 | + err := installClickHooks(instDir, m, testNamespace, false) |
289 | c.Assert(err, IsNil) |
290 | - p := fmt.Sprintf("%s/%s_%s_%s", testSymlinkDir, manifest.Name, "app", manifest.Version) |
291 | + p := fmt.Sprintf("%s/%s.%s_%s_%s", testSymlinkDir, m.Name, testNamespace, "app", m.Version) |
292 | _, err = os.Stat(p) |
293 | c.Assert(err, IsNil) |
294 | symlinkTarget, err := filepath.EvalSymlinks(p) |
295 | c.Assert(err, IsNil) |
296 | c.Assert(symlinkTarget, Equals, path.Join(instDir, "path-to-systemd-file")) |
297 | |
298 | - p = fmt.Sprintf("%s/%s_%s_%s", testSymlinkDir2, manifest.Name, "app", manifest.Version) |
299 | + p = fmt.Sprintf("%s/%s.%s_%s_%s", testSymlinkDir2, m.Name, testNamespace, "app", m.Version) |
300 | _, err = os.Stat(p) |
301 | c.Assert(err, IsNil) |
302 | symlinkTarget, err = filepath.EvalSymlinks(p) |
303 | @@ -168,9 +168,9 @@ |
304 | c.Assert(symlinkTarget, Equals, path.Join(instDir, "path-to-apparmor-file")) |
305 | |
306 | // now ensure we can remove |
307 | - err = removeClickHooks(manifest, false) |
308 | + err = removeClickHooks(m, testNamespace, false) |
309 | c.Assert(err, IsNil) |
310 | - _, err = os.Stat(fmt.Sprintf("%s/%s_%s_%s", testSymlinkDir, manifest.Name, "app", manifest.Version)) |
311 | + _, err = os.Stat(fmt.Sprintf("%s/%s.%s_%s_%s", testSymlinkDir, m.Name, testNamespace, "app", m.Version)) |
312 | c.Assert(err, NotNil) |
313 | } |
314 | |
315 | @@ -1383,10 +1383,10 @@ |
316 | makeClickHook(c, content) |
317 | os.MkdirAll(path.Join(s.tempdir, "/var/lib/systemd/click/"), 0755) |
318 | |
319 | - manifest := clickManifest{ |
320 | + m := &packageYaml{ |
321 | Name: "foo", |
322 | Version: "1.0", |
323 | - Hooks: map[string]clickAppHook{ |
324 | + Integration: map[string]clickAppHook{ |
325 | "app": clickAppHook{ |
326 | "systemd": "path-to-systemd-file", |
327 | }, |
328 | @@ -1399,7 +1399,7 @@ |
329 | return s |
330 | } |
331 | |
332 | - err := installClickHooks(c.MkDir(), manifest, false) |
333 | + err := installClickHooks(c.MkDir(), m, testNamespace, false) |
334 | c.Assert(err, IsNil) |
335 | c.Assert(stripGlobalRootDirWasCalled, Equals, true) |
336 | } |
337 | |
338 | === modified file 'snappy/config.go' |
339 | --- snappy/config.go 2015-05-15 13:33:27 +0000 |
340 | +++ snappy/config.go 2015-05-20 09:49:44 +0000 |
341 | @@ -47,7 +47,7 @@ |
342 | return "", ErrPackageNotFound |
343 | } |
344 | |
345 | - name := Dirname(part) |
346 | + name := QualifiedName(part) |
347 | appArmorProfile := fmt.Sprintf("%s_%s_%s", name, "snappy-config", part.Version()) |
348 | |
349 | return runConfigScript(configScript, appArmorProfile, rawConfig, makeSnapHookEnv(part)) |
350 | |
351 | === modified file 'snappy/datadir.go' |
352 | --- snappy/datadir.go 2015-05-15 13:33:27 +0000 |
353 | +++ snappy/datadir.go 2015-05-20 09:49:44 +0000 |
354 | @@ -32,8 +32,8 @@ |
355 | Version string |
356 | } |
357 | |
358 | -// Dirname returns the filesystem directory name for this SnapDataDir |
359 | -func (dd SnapDataDir) Dirname() string { |
360 | +// QualifiedName returns the filesystem directory name for this SnapDataDir |
361 | +func (dd SnapDataDir) QualifiedName() string { |
362 | if dd.Namespace != "" { |
363 | return dd.Name + "." + dd.Namespace |
364 | } |
365 | |
366 | === modified file 'snappy/datadir_test.go' |
367 | --- snappy/datadir_test.go 2015-05-15 13:33:27 +0000 |
368 | +++ snappy/datadir_test.go 2015-05-20 09:49:44 +0000 |
369 | @@ -115,7 +115,7 @@ |
370 | }) |
371 | } |
372 | |
373 | -func (s *DataDirSuite) TestDataDirDirname(c *C) { |
374 | - c.Check(SnapDataDir{Name: "foo", Namespace: "bar"}.Dirname(), Equals, "foo.bar") |
375 | - c.Check(SnapDataDir{Name: "foo"}.Dirname(), Equals, "foo") |
376 | +func (s *DataDirSuite) TestDataDirQualifiedName(c *C) { |
377 | + c.Check(SnapDataDir{Name: "foo", Namespace: "bar"}.QualifiedName(), Equals, "foo.bar") |
378 | + c.Check(SnapDataDir{Name: "foo"}.QualifiedName(), Equals, "foo") |
379 | } |
380 | |
381 | === modified file 'snappy/install.go' |
382 | --- snappy/install.go 2015-05-19 14:09:19 +0000 |
383 | +++ snappy/install.go 2015-05-20 09:49:44 +0000 |
384 | @@ -107,7 +107,7 @@ |
385 | } |
386 | |
387 | for _, part := range found { |
388 | - cur := FindSnapsByNameAndVersion(Dirname(part), part.Version(), installed) |
389 | + cur := FindSnapsByNameAndVersion(QualifiedName(part), part.Version(), installed) |
390 | if len(cur) != 0 { |
391 | return "", ErrAlreadyInstalled |
392 | } |
393 | |
394 | === modified file 'snappy/install_test.go' |
395 | --- snappy/install_test.go 2015-05-15 13:33:27 +0000 |
396 | +++ snappy/install_test.go 2015-05-20 09:49:44 +0000 |
397 | @@ -118,6 +118,7 @@ |
398 | io.WriteString(w, `{ |
399 | "package_name": "foo", |
400 | "version": "2", |
401 | +"origin": "test", |
402 | "anon_download_url": "`+dlURL+`" |
403 | }`) |
404 | case "/dl": |
405 | |
406 | === modified file 'snappy/parts.go' |
407 | --- snappy/parts.go 2015-05-19 17:32:01 +0000 |
408 | +++ snappy/parts.go 2015-05-20 09:49:44 +0000 |
409 | @@ -43,9 +43,9 @@ |
410 | OemConfig() SystemConfig |
411 | } |
412 | |
413 | -// Dirname of a Part is the Name, in most cases qualified with the |
414 | +// QualifiedName of a Part is the Name, in most cases qualified with the |
415 | // Namespace |
416 | -func Dirname(p Part) string { |
417 | +func QualifiedName(p Part) string { |
418 | if t := p.Type(); t == pkg.TypeFramework || t == pkg.TypeOem { |
419 | return p.Name() |
420 | } |
421 | |
422 | === modified file 'snappy/purge.go' |
423 | --- snappy/purge.go 2015-05-15 13:33:27 +0000 |
424 | +++ snappy/purge.go 2015-05-20 09:49:44 +0000 |
425 | @@ -50,7 +50,7 @@ |
426 | var active []*SnapPart |
427 | |
428 | for _, datadir := range datadirs { |
429 | - yamlPath := filepath.Join(snapAppsDir, datadir.Dirname(), datadir.Version, "meta", "package.yaml") |
430 | + yamlPath := filepath.Join(snapAppsDir, datadir.QualifiedName(), datadir.Version, "meta", "package.yaml") |
431 | part, err := NewInstalledSnapPart(yamlPath, datadir.Namespace) |
432 | if err != nil { |
433 | // no such part installed |
434 | @@ -74,9 +74,9 @@ |
435 | } |
436 | |
437 | for _, datadir := range datadirs { |
438 | - if err := remove(datadir.Dirname(), datadir.Version); err != nil { |
439 | + if err := remove(datadir.QualifiedName(), datadir.Version); err != nil { |
440 | e = err |
441 | - meter.Notify(fmt.Sprintf("unable to purge %s version %s: %s", datadir.Dirname(), datadir.Version, err.Error())) |
442 | + meter.Notify(fmt.Sprintf("unable to purge %s version %s: %s", datadir.QualifiedName(), datadir.Version, err.Error())) |
443 | } |
444 | } |
445 | |
446 | |
447 | === modified file 'snappy/snapp.go' |
448 | --- snappy/snapp.go 2015-05-19 17:32:01 +0000 |
449 | +++ snappy/snapp.go 2015-05-20 09:49:44 +0000 |
450 | @@ -326,6 +326,13 @@ |
451 | return &m, nil |
452 | } |
453 | |
454 | +func (m *packageYaml) qualifiedName(namespace string) string { |
455 | + if m.Type == pkg.TypeFramework || m.Type == pkg.TypeOem { |
456 | + return m.Name |
457 | + } |
458 | + return m.Name + "." + namespace |
459 | +} |
460 | + |
461 | func (m *packageYaml) checkForNameClashes() error { |
462 | d := make(map[string]struct{}) |
463 | for _, bin := range m.Binaries { |
464 | @@ -637,7 +644,7 @@ |
465 | return err |
466 | } |
467 | |
468 | - return RemoveAllHWAccess(Dirname(s)) |
469 | + return RemoveAllHWAccess(QualifiedName(s)) |
470 | } |
471 | |
472 | // Config is used to to configure the snap |
473 | @@ -721,7 +728,7 @@ |
474 | // symlinks (thus requesting aaClickHookCmd regenerate the appropriate bits). |
475 | func (s *SnapPart) RequestAppArmorUpdate(policies, templates map[string]bool) error { |
476 | |
477 | - fullName := Dirname(s) |
478 | + fullName := QualifiedName(s) |
479 | for _, svc := range s.Services() { |
480 | if svc.NeedsAppArmorUpdate(policies, templates) { |
481 | if err := updateAppArmorJSONTimestamp(fullName, svc.Name, s.Version()); err != nil { |
482 | @@ -857,14 +864,23 @@ |
483 | return parts, nil |
484 | } |
485 | |
486 | +func namespaceFromBasedir(basedir string) (s string) { |
487 | + ext := filepath.Ext(filepath.Dir(filepath.Clean(basedir))) |
488 | + if len(ext) < 2 { |
489 | + return "" |
490 | + } |
491 | + |
492 | + return ext[1:] |
493 | +} |
494 | + |
495 | func namespaceFromYamlPath(path string) (string, error) { |
496 | - namespace := filepath.Ext(filepath.Dir(filepath.Join(path, "..", ".."))) |
497 | + namespace := namespaceFromBasedir(filepath.Join(path, "..", "..")) |
498 | |
499 | - if len(namespace) < 1 { |
500 | + if namespace == "" { |
501 | return "", ErrInvalidPart |
502 | } |
503 | |
504 | - return namespace[1:], nil |
505 | + return namespace, nil |
506 | } |
507 | |
508 | // RemoteSnapPart represents a snap available on the server |
509 | @@ -1298,7 +1314,7 @@ |
510 | snapEnv := map[string]string{ |
511 | "SNAP_NAME": part.Name(), |
512 | "SNAP_ORIGIN": part.Namespace(), |
513 | - "SNAP_FULLNAME": Dirname(part), |
514 | + "SNAP_FULLNAME": QualifiedName(part), |
515 | "SNAP_VERSION": part.Version(), |
516 | "SNAP_APP_PATH": part.basedir, |
517 | "SNAP_APP_DATA_PATH": snapDataDir, |
518 | |
519 | === modified file 'snappy/snapp_test.go' |
520 | --- snappy/snapp_test.go 2015-05-19 17:32:01 +0000 |
521 | +++ snappy/snapp_test.go 2015-05-20 09:49:44 +0000 |
522 | @@ -692,6 +692,7 @@ |
523 | |
524 | snap := RemoteSnapPart{} |
525 | snap.pkg.AnonDownloadURL = mockServer.URL + "/snap" |
526 | + snap.pkg.Namespace = testNamespace |
527 | |
528 | p := &MockProgressMeter{} |
529 | name, err := snap.Install(p, 0) |
530 | @@ -1386,3 +1387,28 @@ |
531 | c.Assert(cmds[1], DeepEquals, aCmd{"udevadm", "trigger"}) |
532 | c.Assert(cmds, HasLen, 2) |
533 | } |
534 | + |
535 | +func (s *SnapTestSuite) TestQualifiedNameName(c *C) { |
536 | + packageYaml, err := parsePackageYamlData([]byte(`name: foo |
537 | +version: 1.0 |
538 | +icon: foo.svg |
539 | +vendor: Foo Bar <foo@example.com> |
540 | +`)) |
541 | + c.Assert(err, IsNil) |
542 | + |
543 | + udevName := packageYaml.qualifiedName("mvo") |
544 | + c.Assert(udevName, Equals, "foo.mvo") |
545 | +} |
546 | + |
547 | +func (s *SnapTestSuite) TestQualifiedNameNameFramework(c *C) { |
548 | + packageYaml, err := parsePackageYamlData([]byte(`name: foo |
549 | +version: 1.0 |
550 | +icon: foo.svg |
551 | +type: framework |
552 | +vendor: Foo Bar <foo@example.com> |
553 | +`)) |
554 | + c.Assert(err, IsNil) |
555 | + |
556 | + udevName := packageYaml.qualifiedName("") |
557 | + c.Assert(udevName, Equals, "foo") |
558 | +} |
559 | |
560 | === removed file 'snappy/udev.go' |
561 | --- snappy/udev.go 2015-05-19 17:32:01 +0000 |
562 | +++ snappy/udev.go 1970-01-01 00:00:00 +0000 |
563 | @@ -1,38 +0,0 @@ |
564 | -// -*- Mode: Go; indent-tabs-mode: t -*- |
565 | - |
566 | -/* |
567 | - * Copyright (C) 2014-2015 Canonical Ltd |
568 | - * |
569 | - * This program is free software: you can redistribute it and/or modify |
570 | - * it under the terms of the GNU General Public License version 3 as |
571 | - * published by the Free Software Foundation. |
572 | - * |
573 | - * This program is distributed in the hope that it will be useful, |
574 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
575 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
576 | - * GNU General Public License for more details. |
577 | - * |
578 | - * You should have received a copy of the GNU General Public License |
579 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
580 | - * |
581 | - */ |
582 | - |
583 | -package snappy |
584 | - |
585 | -import ( |
586 | - "fmt" |
587 | - "path/filepath" |
588 | - |
589 | - "launchpad.net/snappy/pkg" |
590 | -) |
591 | - |
592 | -func getUdevPartName(m *packageYaml, baseDir string) (string, error) { |
593 | - if m.Type == pkg.TypeFramework || m.Type == pkg.TypeOem { |
594 | - return m.Name, nil |
595 | - } |
596 | - |
597 | - namespace, err := namespaceFromYamlPath(filepath.Join(baseDir, "meta", "package.yaml")) |
598 | - |
599 | - return fmt.Sprintf("%s.%s", m.Name, namespace), err |
600 | - |
601 | -} |
602 | |
603 | === removed file 'snappy/udev_test.go' |
604 | --- snappy/udev_test.go 2015-05-15 13:33:27 +0000 |
605 | +++ snappy/udev_test.go 1970-01-01 00:00:00 +0000 |
606 | @@ -1,51 +0,0 @@ |
607 | -// -*- Mode: Go; indent-tabs-mode: t -*- |
608 | - |
609 | -/* |
610 | - * Copyright (C) 2014-2015 Canonical Ltd |
611 | - * |
612 | - * This program is free software: you can redistribute it and/or modify |
613 | - * it under the terms of the GNU General Public License version 3 as |
614 | - * published by the Free Software Foundation. |
615 | - * |
616 | - * This program is distributed in the hope that it will be useful, |
617 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
618 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
619 | - * GNU General Public License for more details. |
620 | - * |
621 | - * You should have received a copy of the GNU General Public License |
622 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
623 | - * |
624 | - */ |
625 | - |
626 | -package snappy |
627 | - |
628 | -import ( |
629 | - . "launchpad.net/gocheck" |
630 | -) |
631 | - |
632 | -func (s *SnapTestSuite) TestGetUdevPartName(c *C) { |
633 | - packageYaml, err := parsePackageYamlData([]byte(`name: foo |
634 | -version: 1.0 |
635 | -icon: foo.svg |
636 | -vendor: Foo Bar <foo@example.com> |
637 | -`)) |
638 | - c.Assert(err, IsNil) |
639 | - |
640 | - udevName, err := getUdevPartName(packageYaml, "/apps/foo.mvo/1.0/") |
641 | - c.Assert(err, IsNil) |
642 | - c.Assert(udevName, Equals, "foo.mvo") |
643 | -} |
644 | - |
645 | -func (s *SnapTestSuite) TestGetUdevPartNameFramework(c *C) { |
646 | - packageYaml, err := parsePackageYamlData([]byte(`name: foo |
647 | -version: 1.0 |
648 | -icon: foo.svg |
649 | -type: framework |
650 | -vendor: Foo Bar <foo@example.com> |
651 | -`)) |
652 | - c.Assert(err, IsNil) |
653 | - |
654 | - udevName, err := getUdevPartName(packageYaml, "/apps/foo/1.0/") |
655 | - c.Assert(err, IsNil) |
656 | - c.Assert(udevName, Equals, "foo") |
657 | -} |
Thanks for the branch and the cleanup, really nice. I added some inline comments/ questions/ kudos.