Merge lp:~chipaca/snappy/current-data-dir into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton on 2015-09-29
Status: Merged
Approved by: John Lenton on 2015-09-29
Approved revision: 725
Merged at revision: 725
Proposed branch: lp:~chipaca/snappy/current-data-dir
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 142 lines (+47/-9)
4 files modified
snappy/install_test.go (+11/-2)
snappy/purge_test.go (+6/-2)
snappy/set_test.go (+10/-4)
snappy/snapp.go (+20/-1)
To merge this branch: bzr merge lp:~chipaca/snappy/current-data-dir
Reviewer Review Type Date Requested Status
Leo Arias 2015-09-29 Approve on 2015-09-29
Review via email: mp+272691@code.launchpad.net

Commit Message

Have a “current” symlink in the system data dir ($SNAP_APP_DATA_DIR).

Description of the Change

This adds a “current” symlink to the snap datadir.

Not to the home datadir though. That's more complicated.

To post a comment you must log in.
Leo Arias (elopio) wrote :

the code looks correct to me. I installed hello-world with snappy from trunk and it does not create the link in /var/lib/apps/hello-world.canonical/. I installed it with snappy from this branch and the link is created. I removed the branch and the link is removed. All good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/install_test.go'
2--- snappy/install_test.go 2015-06-29 20:21:38 +0000
3+++ snappy/install_test.go 2015-09-29 06:07:50 +0000
4@@ -78,8 +78,13 @@
5 s.installThree(c, AllowUnauthenticated|DoInstallGC)
6
7 globs, err := filepath.Glob(filepath.Join(snapAppsDir, "foo.sideload", "*"))
8- c.Assert(err, IsNil)
9- c.Assert(globs, HasLen, 2+1) // +1 for "current"
10+ c.Check(err, IsNil)
11+ c.Check(globs, HasLen, 2+1) // +1 for "current"
12+
13+ // gc should leave one more data than app
14+ globs, err = filepath.Glob(filepath.Join(snapDataDir, "foo.sideload", "*"))
15+ c.Check(err, IsNil)
16+ c.Check(globs, HasLen, 3+1) // +1 for "current"
17 }
18
19 // check that if flags does not include DoInstallGC, no gc is done
20@@ -89,6 +94,10 @@
21 globs, err := filepath.Glob(filepath.Join(snapAppsDir, "foo.sideload", "*"))
22 c.Assert(err, IsNil)
23 c.Assert(globs, HasLen, 3+1) // +1 for "current"
24+
25+ globs, err = filepath.Glob(filepath.Join(snapDataDir, "foo.sideload", "*"))
26+ c.Check(err, IsNil)
27+ c.Check(globs, HasLen, 3+1) // +1 for "current"
28 }
29
30 func (s *SnapTestSuite) TestInstallAppTwiceFails(c *C) {
31
32=== modified file 'snappy/purge_test.go'
33--- snappy/purge_test.go 2015-06-09 19:11:54 +0000
34+++ snappy/purge_test.go 2015-09-29 06:07:50 +0000
35@@ -114,10 +114,12 @@
36 inter := &MockProgressMeter{}
37 ddir, part := s.mkpkg(c)
38 c.Assert(part.activate(true, inter), IsNil)
39+ canary := filepath.Join(ddir, "canary")
40+ c.Assert(os.Mkdir(canary, 0755), IsNil)
41
42 err := Purge("hello-app", DoPurgeActive, inter)
43 c.Check(err, IsNil)
44- c.Check(helpers.FileExists(ddir), Equals, false)
45+ c.Check(helpers.FileExists(canary), Equals, false)
46 c.Check(inter.notified, HasLen, 0)
47 }
48
49@@ -125,6 +127,8 @@
50 inter := &MockProgressMeter{}
51 ddir, part := s.mkpkg(c, "v1", "services:\n - name: svc")
52 c.Assert(part.activate(true, inter), IsNil)
53+ canary := filepath.Join(ddir, "canary")
54+ c.Assert(os.Mkdir(canary, 0755), IsNil)
55
56 called := [][]string{}
57 systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
58@@ -134,7 +138,7 @@
59
60 err := Purge("hello-app", DoPurgeActive, inter)
61 c.Check(err, IsNil)
62- c.Check(helpers.FileExists(ddir), Equals, false)
63+ c.Check(helpers.FileExists(canary), Equals, false)
64 c.Assert(inter.notified, HasLen, 1)
65 c.Check(inter.notified[0], Matches, `Waiting for .* to stop.`)
66 rv := make(map[string]int)
67
68=== modified file 'snappy/set_test.go'
69--- snappy/set_test.go 2015-06-02 20:46:07 +0000
70+++ snappy/set_test.go 2015-09-29 06:07:50 +0000
71@@ -22,7 +22,6 @@
72 import (
73 "os"
74 "path/filepath"
75- "strings"
76
77 . "gopkg.in/check.v1"
78
79@@ -80,7 +79,12 @@
80
81 path, err := filepath.EvalSymlinks(filepath.Join(snapAppsDir, fooComposedName, "current"))
82 c.Assert(err, IsNil)
83- c.Assert(strings.HasSuffix(path, "/"+fooComposedName+"/2.0"), Equals, true)
84+ c.Check(path, Equals, filepath.Join(snapAppsDir, fooComposedName, "2.0"))
85+
86+ path, err = filepath.EvalSymlinks(filepath.Join(snapDataDir, fooComposedName, "current"))
87+ c.Assert(err, IsNil)
88+ c.Check(path, Equals, filepath.Join(snapDataDir, fooComposedName, "2.0"))
89+
90 meter := &MockProgressMeter{}
91
92 // setActive has some ugly print
93@@ -94,6 +98,8 @@
94
95 err = makeSnapActiveByNameAndVersion("foo", "1.0", meter)
96 c.Assert(err, IsNil)
97- path, err = filepath.EvalSymlinks(filepath.Join(snapAppsDir, fooComposedName, "current"))
98- c.Assert(strings.HasSuffix(path, "/"+fooComposedName+"/1.0"), Equals, true)
99+ path, _ = filepath.EvalSymlinks(filepath.Join(snapAppsDir, fooComposedName, "current"))
100+ c.Check(path, Equals, filepath.Join(snapAppsDir, fooComposedName, "1.0"))
101+ path, _ = filepath.EvalSymlinks(filepath.Join(snapDataDir, fooComposedName, "current"))
102+ c.Check(path, Equals, filepath.Join(snapDataDir, fooComposedName, "1.0"))
103 }
104
105=== modified file 'snappy/snapp.go'
106--- snappy/snapp.go 2015-09-16 11:23:27 +0000
107+++ snappy/snapp.go 2015-09-29 06:07:50 +0000
108@@ -1036,8 +1036,22 @@
109 logger.Noticef("Failed to remove %q: %v", currentActiveSymlink, err)
110 }
111
112+ dbase := filepath.Join(snapDataDir, QualifiedName(s))
113+ currentDataSymlink := filepath.Join(dbase, "current")
114+ if err := os.Remove(currentDataSymlink); err != nil && !os.IsNotExist(err) {
115+ logger.Noticef("Failed to remove %q: %v", currentDataSymlink, err)
116+ }
117+
118 // symlink is relative to parent dir
119- return os.Symlink(filepath.Base(s.basedir), currentActiveSymlink)
120+ if err := os.Symlink(filepath.Base(s.basedir), currentActiveSymlink); err != nil {
121+ return err
122+ }
123+
124+ if err := os.MkdirAll(filepath.Join(dbase, s.Version()), 0755); err != nil {
125+ return err
126+ }
127+
128+ return os.Symlink(filepath.Base(s.basedir), currentDataSymlink)
129 }
130
131 func (s *SnapPart) deactivate(inhibitHooks bool, inter interacter) error {
132@@ -1083,6 +1097,11 @@
133 logger.Noticef("Failed to remove %q: %v", currentSymlink, err)
134 }
135
136+ currentDataSymlink := filepath.Join(snapDataDir, QualifiedName(s), "current")
137+ if err := os.Remove(currentDataSymlink); err != nil && !os.IsNotExist(err) {
138+ logger.Noticef("Failed to remove %q: %v", currentDataSymlink, err)
139+ }
140+
141 return nil
142 }
143

Subscribers

People subscribed via source and target branches