Merge lp:~sergiusens/goget-ubuntu-touch/unmapErr into lp:goget-ubuntu-touch

Proposed by Sergio Schvezov on 2015-07-09
Status: Merged
Approved by: John Lenton on 2015-07-10
Approved revision: 200
Merged at revision: 200
Proposed branch: lp:~sergiusens/goget-ubuntu-touch/unmapErr
Merge into: lp:goget-ubuntu-touch
Diff against target: 114 lines (+28/-21)
2 files modified
diskimage/common.go (+26/-9)
ubuntu-device-flash/snappy.go (+2/-12)
To merge this branch: bzr merge lp:~sergiusens/goget-ubuntu-touch/unmapErr
Reviewer Review Type Date Requested Status
John Lenton 2015-07-09 Approve on 2015-07-10
Review via email: mp+264250@code.launchpad.net

Commit Message

Expose unmap error after formatting

To post a comment you must log in.
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'diskimage/common.go'
2--- diskimage/common.go 2015-06-23 10:23:50 +0000
3+++ diskimage/common.go 2015-07-09 10:02:11 +0000
4@@ -60,8 +60,6 @@
5 Unmount() error
6 Format() error
7 Partition() error
8- Map() error
9- Unmap() error
10 BaseMount() string
11 }
12
13@@ -200,7 +198,7 @@
14
15 // Mount mounts the image. This also maps the loop device.
16 func (img *BaseImage) Mount() error {
17- if err := img.Map(); err != nil {
18+ if err := img.doMap(); err != nil {
19 return err
20 }
21
22@@ -260,6 +258,12 @@
23
24 // Unmount unmounts the image. This also unmaps the loop device.
25 func (img *BaseImage) Unmount() error {
26+ defer func() {
27+ if isMapped(img.parts) {
28+ fmt.Println("WARNING: could not unmap partitions")
29+ }
30+ }()
31+
32 if img.baseMount == "" {
33 panic("No base mountpoint set")
34 }
35@@ -285,11 +289,11 @@
36 }
37 img.baseMount = ""
38
39- return img.Unmap()
40+ return img.doUnmap()
41 }
42
43-// Map maps the image to loop devices
44-func (img *BaseImage) Map() error {
45+// doMap maps the image to loop devices
46+func (img *BaseImage) doMap() error {
47 if isMapped(img.parts) {
48 panic("cannot double map partitions")
49 }
50@@ -332,8 +336,8 @@
51 return nil
52 }
53
54-//Unmap destroys loop devices for the partitions
55-func (img *BaseImage) Unmap() error {
56+// doUnmap destroys loop devices for the partitions
57+func (img *BaseImage) doUnmap() error {
58 if img.baseMount != "" {
59 panic("cannot unmap mounted partitions")
60 }
61@@ -355,7 +359,20 @@
62
63 // Format formats the image following the partition types and labels them
64 // accordingly.
65-func (img BaseImage) Format() error {
66+func (img BaseImage) Format() (err error) {
67+ if err := img.doMap(); err != nil {
68+ return err
69+ }
70+ defer func() {
71+ if errUnmap := img.doUnmap(); errUnmap != nil {
72+ if err == nil {
73+ err = errUnmap
74+ } else {
75+ fmt.Println("WARNING: could not unmap partitions after error:", errUnmap)
76+ }
77+ }
78+ }()
79+
80 for _, part := range img.parts {
81 dev := filepath.Join("/dev/mapper", part.loop)
82
83
84=== modified file 'ubuntu-device-flash/snappy.go'
85--- ubuntu-device-flash/snappy.go 2015-06-24 12:53:54 +0000
86+++ ubuntu-device-flash/snappy.go 2015-07-09 10:02:11 +0000
87@@ -402,7 +402,8 @@
88 }
89 defer sysutils.DropPrivs()
90
91- if err := format(s.img); err != nil {
92+ printOut("Formatting...")
93+ if err := s.img.Format(); err != nil {
94 return err
95 }
96
97@@ -413,17 +414,6 @@
98 return nil
99 }
100
101-func format(img diskimage.Image) error {
102- printOut("Mapping...")
103- if err := img.Map(); err != nil {
104- return fmt.Errorf("issue while mapping partitions: %s", err)
105- }
106- defer img.Unmap()
107-
108- printOut("Formatting...")
109- return img.Format()
110-}
111-
112 func (s Snapper) printSummary() {
113 fmt.Println("New image complete")
114 fmt.Println("Summary:")

Subscribers

People subscribed via source and target branches