Merge lp:~chipaca/snappy/snappy-tar-pack-mknod into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 450
Merged at revision: 449
Proposed branch: lp:~chipaca/snappy/snappy-tar-pack-mknod
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 210 lines (+108/-3)
6 files modified
clickdeb/deb.go (+13/-2)
clickdeb/deb_test.go (+14/-1)
helpers/cp.go (+36/-0)
helpers/cp_test.go (+20/-0)
snappy/build.go (+12/-0)
snappy/build_test.go (+13/-0)
To merge this branch: bzr merge lp:~chipaca/snappy/snappy-tar-pack-mknod
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
Review via email: mp+258536@code.launchpad.net

Commit message

Add support for adding devices in snappy build.

Description of the change

This is lp:~mvo/snappy/snappy-tar-pack-mknod merged with trunk and conflcits resolved.

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

one comment useful for troubleshooting, otherwise looks good and thanks!

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

good, just a cosmetic, but good good

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Michael Vogt (mvo) wrote :

reply to inline comment

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clickdeb/deb.go'
2--- clickdeb/deb.go 2015-04-23 11:12:32 +0000
3+++ clickdeb/deb.go 2015-05-07 20:37:19 +0000
4@@ -289,8 +289,8 @@
5 }
6
7 // check if we support this type
8- if !st.Mode().IsRegular() && !helpers.IsSymlink(st.Mode()) && !st.Mode().IsDir() {
9- return nil
10+ if !st.Mode().IsRegular() && !helpers.IsSymlink(st.Mode()) && !st.Mode().IsDir() && !helpers.IsDevice(st.Mode()) {
11+ return fmt.Errorf("unsupported file type for %s", path)
12 }
13
14 // check our exclude function
15@@ -307,6 +307,17 @@
16 return err
17 }
18
19+ // tar.FileInfoHeader does include the fact that its a
20+ // char/block device, but does not set major/minor :/
21+ if helpers.IsDevice(st.Mode()) {
22+ major, minor, err := helpers.MajorMinor(st)
23+ if err != nil {
24+ return err
25+ }
26+ hdr.Devmajor = int64(major)
27+ hdr.Devminor = int64(minor)
28+ }
29+
30 // exclude "."
31 relativePath := "." + path[len(sourceDir):]
32 if relativePath == "." {
33
34=== modified file 'clickdeb/deb_test.go'
35--- clickdeb/deb_test.go 2015-04-13 20:58:56 +0000
36+++ clickdeb/deb_test.go 2015-05-07 20:37:19 +0000
37@@ -25,6 +25,7 @@
38 "path/filepath"
39 "regexp"
40 "strings"
41+ "syscall"
42 "testing"
43
44 . "launchpad.net/gocheck"
45@@ -175,7 +176,6 @@
46 // create tar
47 tempdir := c.MkDir()
48 tarfile := filepath.Join(tempdir, "data.tar.xz")
49- tarfile = "/tmp/lala.tar.xz"
50 err = tarCreate(tarfile, builddir, func(path string) bool {
51 return !strings.HasSuffix(path, "exclude-me")
52 })
53@@ -213,3 +213,16 @@
54 c.Assert(err, IsNil)
55 c.Assert(r.Match(output), Equals, false)
56 }
57+
58+func (s *ClickDebTestSuite) TestTarCreateUnknownTypeFailsWithError(c *C) {
59+
60+ builddir := c.MkDir()
61+ err := syscall.Mkfifo(filepath.Join(builddir, "fifo"), 0644)
62+ c.Assert(err, IsNil)
63+
64+ tempdir := c.MkDir()
65+ tarfile := filepath.Join(tempdir, "data.tar.xz")
66+
67+ err = tarCreate(tarfile, builddir, nil)
68+ c.Assert(err, ErrorMatches, "unsupported file type for.*")
69+}
70
71=== modified file 'helpers/cp.go'
72--- helpers/cp.go 2015-05-07 10:34:05 +0000
73+++ helpers/cp.go 2015-05-07 20:37:19 +0000
74@@ -20,6 +20,7 @@
75 import (
76 "fmt"
77 "os"
78+ "os/exec"
79 )
80
81 // CopyFlag is used to tweak the behaviour of CopyFile
82@@ -89,3 +90,38 @@
83
84 return nil
85 }
86+
87+// CopySpecialFile is used to copy all the things that are not files
88+// (like device nodes, named pipes etc)
89+func CopySpecialFile(path, dest string) error {
90+ cmd := exec.Command("cp", "-av", path, dest)
91+ if output, err := cmd.CombinedOutput(); err != nil {
92+ if exitCode, err := ExitCode(err); err == nil {
93+ return &ErrCopySpecialFile{
94+ exitCode: exitCode,
95+ output: output,
96+ }
97+ }
98+ return &ErrCopySpecialFile{
99+ err: err,
100+ output: output,
101+ }
102+ }
103+
104+ return nil
105+}
106+
107+// ErrCopySpecialFile is returned if a special file copy fails
108+type ErrCopySpecialFile struct {
109+ exitCode int
110+ output []byte
111+ err error
112+}
113+
114+func (e ErrCopySpecialFile) Error() string {
115+ if e.err == nil {
116+ return fmt.Sprintf("failed to copy device node: %q (%v)", e.output, e.exitCode)
117+ }
118+
119+ return fmt.Sprintf("failed to copy device node: %q (%v)", e.output, e.err)
120+}
121
122=== modified file 'helpers/cp_test.go'
123--- helpers/cp_test.go 2015-05-02 14:40:45 +0000
124+++ helpers/cp_test.go 2015-05-07 20:37:19 +0000
125@@ -23,6 +23,7 @@
126 "os"
127 "path/filepath"
128 "strings"
129+ "syscall"
130 "time"
131
132 . "launchpad.net/gocheck"
133@@ -167,3 +168,22 @@
134 func (mockstat) ModTime() time.Time { return time.Now() }
135 func (mockstat) IsDir() bool { return false }
136 func (mockstat) Sys() interface{} { return nil }
137+
138+func (s *cpSuite) TestCopySpecialFileSimple(c *C) {
139+ src := filepath.Join(c.MkDir(), "fifo")
140+ err := syscall.Mkfifo(src, 0644)
141+ c.Assert(err, IsNil)
142+ dst := filepath.Join(c.MkDir(), "copied-fifo")
143+
144+ err = CopySpecialFile(src, dst)
145+ c.Assert(err, IsNil)
146+
147+ st, err := os.Stat(dst)
148+ c.Assert(err, IsNil)
149+ c.Assert((st.Mode() & os.ModeNamedPipe), Equals, os.ModeNamedPipe)
150+}
151+
152+func (s *cpSuite) TestCopySpecialFileErrors(c *C) {
153+ err := CopySpecialFile("no-such-file", "no-such-target")
154+ c.Assert(err, ErrorMatches, ".*No such file or directory.*")
155+}
156
157=== modified file 'snappy/build.go'
158--- snappy/build.go 2015-05-07 16:27:46 +0000
159+++ snappy/build.go 2015-05-07 20:37:19 +0000
160@@ -412,10 +412,22 @@
161 }
162
163 dest := filepath.Join(buildDir, path[len(sourceDir):])
164+
165+ // handle dirs
166 if info.IsDir() {
167 return os.Mkdir(dest, info.Mode())
168 }
169
170+ // handle char/block devices
171+ if helpers.IsDevice(info.Mode()) {
172+ return helpers.CopySpecialFile(path, dest)
173+ }
174+
175+ // fail if its unsupported
176+ if !info.Mode().IsRegular() {
177+ return fmt.Errorf("can not handle type of file %s", path)
178+ }
179+
180 // it's a file. Maybe we can link it?
181 if os.Link(path, dest) == nil {
182 // whee
183
184=== modified file 'snappy/build_test.go'
185--- snappy/build_test.go 2015-05-07 10:34:05 +0000
186+++ snappy/build_test.go 2015-05-07 20:37:19 +0000
187@@ -23,6 +23,7 @@
188 "os/exec"
189 "path/filepath"
190 "strings"
191+ "syscall"
192
193 "launchpad.net/snappy/helpers"
194
195@@ -462,3 +463,15 @@
196 c.Assert(strings.Contains(string(readFiles), `drwxrwxrwx`), Equals, true)
197 c.Assert(strings.Contains(string(readFiles), `-rw-rw-rw-`), Equals, true)
198 }
199+
200+func (s *SnapTestSuite) TestBuildFailsForUnknownType(c *C) {
201+ sourceDir := makeExampleSnapSourceDir(c, `name: hello
202+version: 1.0.1
203+vendor: Foo <foo@example.com>
204+`)
205+ err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644)
206+ c.Assert(err, IsNil)
207+
208+ _, err = Build(sourceDir, "")
209+ c.Assert(err, ErrorMatches, "can not handle type of file .*")
210+}

Subscribers

People subscribed via source and target branches