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
=== modified file 'clickdeb/deb.go'
--- clickdeb/deb.go 2015-04-23 11:12:32 +0000
+++ clickdeb/deb.go 2015-05-07 20:37:19 +0000
@@ -289,8 +289,8 @@
289 }289 }
290290
291 // check if we support this type291 // check if we support this type
292 if !st.Mode().IsRegular() && !helpers.IsSymlink(st.Mode()) && !st.Mode().IsDir() {292 if !st.Mode().IsRegular() && !helpers.IsSymlink(st.Mode()) && !st.Mode().IsDir() && !helpers.IsDevice(st.Mode()) {
293 return nil293 return fmt.Errorf("unsupported file type for %s", path)
294 }294 }
295295
296 // check our exclude function296 // check our exclude function
@@ -307,6 +307,17 @@
307 return err307 return err
308 }308 }
309309
310 // tar.FileInfoHeader does include the fact that its a
311 // char/block device, but does not set major/minor :/
312 if helpers.IsDevice(st.Mode()) {
313 major, minor, err := helpers.MajorMinor(st)
314 if err != nil {
315 return err
316 }
317 hdr.Devmajor = int64(major)
318 hdr.Devminor = int64(minor)
319 }
320
310 // exclude "."321 // exclude "."
311 relativePath := "." + path[len(sourceDir):]322 relativePath := "." + path[len(sourceDir):]
312 if relativePath == "." {323 if relativePath == "." {
313324
=== modified file 'clickdeb/deb_test.go'
--- clickdeb/deb_test.go 2015-04-13 20:58:56 +0000
+++ clickdeb/deb_test.go 2015-05-07 20:37:19 +0000
@@ -25,6 +25,7 @@
25 "path/filepath"25 "path/filepath"
26 "regexp"26 "regexp"
27 "strings"27 "strings"
28 "syscall"
28 "testing"29 "testing"
2930
30 . "launchpad.net/gocheck"31 . "launchpad.net/gocheck"
@@ -175,7 +176,6 @@
175 // create tar176 // create tar
176 tempdir := c.MkDir()177 tempdir := c.MkDir()
177 tarfile := filepath.Join(tempdir, "data.tar.xz")178 tarfile := filepath.Join(tempdir, "data.tar.xz")
178 tarfile = "/tmp/lala.tar.xz"
179 err = tarCreate(tarfile, builddir, func(path string) bool {179 err = tarCreate(tarfile, builddir, func(path string) bool {
180 return !strings.HasSuffix(path, "exclude-me")180 return !strings.HasSuffix(path, "exclude-me")
181 })181 })
@@ -213,3 +213,16 @@
213 c.Assert(err, IsNil)213 c.Assert(err, IsNil)
214 c.Assert(r.Match(output), Equals, false)214 c.Assert(r.Match(output), Equals, false)
215}215}
216
217func (s *ClickDebTestSuite) TestTarCreateUnknownTypeFailsWithError(c *C) {
218
219 builddir := c.MkDir()
220 err := syscall.Mkfifo(filepath.Join(builddir, "fifo"), 0644)
221 c.Assert(err, IsNil)
222
223 tempdir := c.MkDir()
224 tarfile := filepath.Join(tempdir, "data.tar.xz")
225
226 err = tarCreate(tarfile, builddir, nil)
227 c.Assert(err, ErrorMatches, "unsupported file type for.*")
228}
216229
=== modified file 'helpers/cp.go'
--- helpers/cp.go 2015-05-07 10:34:05 +0000
+++ helpers/cp.go 2015-05-07 20:37:19 +0000
@@ -20,6 +20,7 @@
20import (20import (
21 "fmt"21 "fmt"
22 "os"22 "os"
23 "os/exec"
23)24)
2425
25// CopyFlag is used to tweak the behaviour of CopyFile26// CopyFlag is used to tweak the behaviour of CopyFile
@@ -89,3 +90,38 @@
8990
90 return nil91 return nil
91}92}
93
94// CopySpecialFile is used to copy all the things that are not files
95// (like device nodes, named pipes etc)
96func CopySpecialFile(path, dest string) error {
97 cmd := exec.Command("cp", "-av", path, dest)
98 if output, err := cmd.CombinedOutput(); err != nil {
99 if exitCode, err := ExitCode(err); err == nil {
100 return &ErrCopySpecialFile{
101 exitCode: exitCode,
102 output: output,
103 }
104 }
105 return &ErrCopySpecialFile{
106 err: err,
107 output: output,
108 }
109 }
110
111 return nil
112}
113
114// ErrCopySpecialFile is returned if a special file copy fails
115type ErrCopySpecialFile struct {
116 exitCode int
117 output []byte
118 err error
119}
120
121func (e ErrCopySpecialFile) Error() string {
122 if e.err == nil {
123 return fmt.Sprintf("failed to copy device node: %q (%v)", e.output, e.exitCode)
124 }
125
126 return fmt.Sprintf("failed to copy device node: %q (%v)", e.output, e.err)
127}
92128
=== modified file 'helpers/cp_test.go'
--- helpers/cp_test.go 2015-05-02 14:40:45 +0000
+++ helpers/cp_test.go 2015-05-07 20:37:19 +0000
@@ -23,6 +23,7 @@
23 "os"23 "os"
24 "path/filepath"24 "path/filepath"
25 "strings"25 "strings"
26 "syscall"
26 "time"27 "time"
2728
28 . "launchpad.net/gocheck"29 . "launchpad.net/gocheck"
@@ -167,3 +168,22 @@
167func (mockstat) ModTime() time.Time { return time.Now() }168func (mockstat) ModTime() time.Time { return time.Now() }
168func (mockstat) IsDir() bool { return false }169func (mockstat) IsDir() bool { return false }
169func (mockstat) Sys() interface{} { return nil }170func (mockstat) Sys() interface{} { return nil }
171
172func (s *cpSuite) TestCopySpecialFileSimple(c *C) {
173 src := filepath.Join(c.MkDir(), "fifo")
174 err := syscall.Mkfifo(src, 0644)
175 c.Assert(err, IsNil)
176 dst := filepath.Join(c.MkDir(), "copied-fifo")
177
178 err = CopySpecialFile(src, dst)
179 c.Assert(err, IsNil)
180
181 st, err := os.Stat(dst)
182 c.Assert(err, IsNil)
183 c.Assert((st.Mode() & os.ModeNamedPipe), Equals, os.ModeNamedPipe)
184}
185
186func (s *cpSuite) TestCopySpecialFileErrors(c *C) {
187 err := CopySpecialFile("no-such-file", "no-such-target")
188 c.Assert(err, ErrorMatches, ".*No such file or directory.*")
189}
170190
=== modified file 'snappy/build.go'
--- snappy/build.go 2015-05-07 16:27:46 +0000
+++ snappy/build.go 2015-05-07 20:37:19 +0000
@@ -412,10 +412,22 @@
412 }412 }
413413
414 dest := filepath.Join(buildDir, path[len(sourceDir):])414 dest := filepath.Join(buildDir, path[len(sourceDir):])
415
416 // handle dirs
415 if info.IsDir() {417 if info.IsDir() {
416 return os.Mkdir(dest, info.Mode())418 return os.Mkdir(dest, info.Mode())
417 }419 }
418420
421 // handle char/block devices
422 if helpers.IsDevice(info.Mode()) {
423 return helpers.CopySpecialFile(path, dest)
424 }
425
426 // fail if its unsupported
427 if !info.Mode().IsRegular() {
428 return fmt.Errorf("can not handle type of file %s", path)
429 }
430
419 // it's a file. Maybe we can link it?431 // it's a file. Maybe we can link it?
420 if os.Link(path, dest) == nil {432 if os.Link(path, dest) == nil {
421 // whee433 // whee
422434
=== modified file 'snappy/build_test.go'
--- snappy/build_test.go 2015-05-07 10:34:05 +0000
+++ snappy/build_test.go 2015-05-07 20:37:19 +0000
@@ -23,6 +23,7 @@
23 "os/exec"23 "os/exec"
24 "path/filepath"24 "path/filepath"
25 "strings"25 "strings"
26 "syscall"
2627
27 "launchpad.net/snappy/helpers"28 "launchpad.net/snappy/helpers"
2829
@@ -462,3 +463,15 @@
462 c.Assert(strings.Contains(string(readFiles), `drwxrwxrwx`), Equals, true)463 c.Assert(strings.Contains(string(readFiles), `drwxrwxrwx`), Equals, true)
463 c.Assert(strings.Contains(string(readFiles), `-rw-rw-rw-`), Equals, true)464 c.Assert(strings.Contains(string(readFiles), `-rw-rw-rw-`), Equals, true)
464}465}
466
467func (s *SnapTestSuite) TestBuildFailsForUnknownType(c *C) {
468 sourceDir := makeExampleSnapSourceDir(c, `name: hello
469version: 1.0.1
470vendor: Foo <foo@example.com>
471`)
472 err := syscall.Mkfifo(filepath.Join(sourceDir, "fifo"), 0644)
473 c.Assert(err, IsNil)
474
475 _, err = Build(sourceDir, "")
476 c.Assert(err, ErrorMatches, "can not handle type of file .*")
477}

Subscribers

People subscribed via source and target branches