Merge lp:~mandel/ciborium/ensure-dirs-created into lp:ciborium

Proposed by Manuel de la Peña
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 116
Merged at revision: 102
Proposed branch: lp:~mandel/ciborium/ensure-dirs-created
Merge into: lp:ciborium
Prerequisite: lp:~mandel/ciborium/increase-coverage
Diff against target: 137 lines (+49/-26)
2 files modified
cmd/ciborium/main.go (+24/-1)
udisks2/udisks2.go (+25/-25)
To merge this branch: bzr merge lp:~mandel/ciborium/ensure-dirs-created
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+251264@code.launchpad.net

Commit message

Ensure that the default dirs are created after the sd card has been formatted.

Description of the change

Ensure that the default dirs are created after the sd card has been formatted. When testing, do take a look at the sd card and ensure that the Downloads, Documents.. folders are present.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
116. By Manuel de la Peña

Link bug.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

LGTM, and works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/ciborium/main.go'
2--- cmd/ciborium/main.go 2015-02-05 15:43:44 +0000
3+++ cmd/ciborium/main.go 2015-03-02 12:08:19 +0000
4@@ -165,7 +165,7 @@
5 notificationHandler := notifications.NewLegacyHandler(sessionBus, "ciborium")
6 notifyFree := buildFreeNotify(notificationHandler)
7
8- blockAdded, blockError := udisks2.SubscribeAddEvents()
9+ blockAdded, formatCompleted, blockError := udisks2.SubscribeAddEvents()
10 mountRemoved := udisks2.SubscribeRemoveEvents()
11
12 go func() {
13@@ -201,6 +201,28 @@
14 msgStorageFail.Body,
15 errorIcon,
16 )
17+ case f := <-formatCompleted:
18+ if m, err := udisks2.Mount(f); err != nil {
19+ log.Println("Cannot mount", f.Path, "due to:", err)
20+ n = notificationHandler.NewStandardPushMessage(
21+ msgStorageFail.Summary,
22+ msgStorageFail.Body,
23+ errorIcon,
24+ )
25+ } else {
26+ log.Println("Mounted", f.Path, "as", m)
27+ n = notificationHandler.NewStandardPushMessage(
28+ msgStorageSuccess.Summary,
29+ msgStorageSuccess.Body,
30+ sdCardIcon,
31+ )
32+
33+ if err := createStandardHomeDirs(m); err != nil {
34+ log.Println("Failed to create standard dir layout:", err)
35+ }
36+
37+ mw.set(mountpoint(m), true)
38+ }
39 case m := <-mountRemoved:
40 log.Println("Path removed", m)
41 n = notificationHandler.NewStandardPushMessage(
42@@ -236,6 +258,7 @@
43 // createStandardHomeDirs creates directories reflecting a standard home, these
44 // directories are Documents, Downloads, Music, Pictures and Videos
45 func createStandardHomeDirs(mountpoint string) error {
46+ log.Println("createStandardHomeDirs(", mountpoint, ")")
47 for _, node := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
48 dir := filepath.Join(mountpoint, node)
49
50
51=== modified file 'udisks2/udisks2.go'
52--- udisks2/udisks2.go 2015-03-02 12:08:19 +0000
53+++ udisks2/udisks2.go 2015-03-02 12:08:19 +0000
54@@ -61,21 +61,22 @@
55 type mountpointMap map[dbus.ObjectPath]string
56
57 type UDisks2 struct {
58- conn *dbus.Connection
59- validFS sort.StringSlice
60- blockAdded chan *Event
61- driveAdded *dbus.SignalWatch
62- mountRemoved chan string
63- blockError chan error
64- driveRemoved *dbus.SignalWatch
65- blockDevice chan bool
66- drives driveMap
67- mountpoints mountpointMap
68- mapLock sync.Mutex
69- startLock sync.Mutex
70- dispatcher *dispatcher
71- jobs *jobManager
72- pendingMounts []string
73+ conn *dbus.Connection
74+ validFS sort.StringSlice
75+ blockAdded chan *Event
76+ driveAdded *dbus.SignalWatch
77+ mountRemoved chan string
78+ blockError chan error
79+ driveRemoved *dbus.SignalWatch
80+ blockDevice chan bool
81+ drives driveMap
82+ mountpoints mountpointMap
83+ mapLock sync.Mutex
84+ startLock sync.Mutex
85+ dispatcher *dispatcher
86+ jobs *jobManager
87+ pendingMounts []string
88+ formatCompleted chan *Event
89 }
90
91 func NewStorageWatcher(conn *dbus.Connection, filesystems ...string) (u *UDisks2) {
92@@ -90,10 +91,11 @@
93 return u
94 }
95
96-func (u *UDisks2) SubscribeAddEvents() (<-chan *Event, <-chan error) {
97+func (u *UDisks2) SubscribeAddEvents() (<-chan *Event, <-chan *Event, <-chan error) {
98 u.blockAdded = make(chan *Event)
99 u.blockError = make(chan error)
100- return u.blockAdded, u.blockError
101+ u.formatCompleted = make(chan *Event)
102+ return u.blockAdded, u.formatCompleted, u.blockError
103 }
104
105 func (u *UDisks2) SubscribeRemoveEvents() <-chan string {
106@@ -119,6 +121,7 @@
107 }
108
109 u.mountpoints[s.Path] = mountpoint
110+ log.Println("Mounth path for '", s.Path, "' set to be", mountpoint)
111 return mountpoint, err
112 }
113
114@@ -305,18 +308,15 @@
115 }
116
117 func (u *UDisks2) processAddEvent(s *Event) error {
118+ log.Println("processAddEvents(", s.Path, s.Props, s.Interfaces, ")")
119 u.mapLock.Lock()
120 defer u.mapLock.Unlock()
121+
122 pos := sort.SearchStrings(u.pendingMounts, string(s.Path))
123 if pos != len(u.pendingMounts) && s.Props.isFilesystem() {
124- log.Println("Mount path", s.Path)
125- _, err := u.Mount(s)
126- u.pendingMounts = append(u.pendingMounts[:pos], u.pendingMounts[pos+1:]...)
127- if err != nil {
128- u.blockError <- err
129- } else {
130- u.blockAdded <- s
131- }
132+ log.Println("Path", s.Path, "must be remounted.")
133+ u.formatCompleted <- s
134+ return nil
135 }
136 if isBlockDevice, err := u.drives.addInterface(s); err != nil {
137 return err

Subscribers

People subscribed via source and target branches