Merge lp:~sergiusens/ciborium/remove_notification into lp:ciborium

Proposed by Sergio Schvezov
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 17
Merged at revision: 15
Proposed branch: lp:~sergiusens/ciborium/remove_notification
Merge into: lp:ciborium
Prerequisite: lp:~sergiusens/ciborium/1354671
Diff against target: 250 lines (+106/-35)
3 files modified
cmd/ciborium/main.go (+24/-8)
po/ciborium.pot (+18/-5)
udisks2/udisks2.go (+64/-22)
To merge this branch: bzr merge lp:~sergiusens/ciborium/remove_notification
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Review via email: mp+230567@code.launchpad.net

Commit message

Adding a notification for when a device is 'unmounted'

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) :
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 2014-08-06 19:31:54 +0000
3+++ cmd/ciborium/main.go 2014-08-13 02:40:31 +0000
4@@ -58,6 +58,15 @@
5 // with regards to the failure when adding a storage device.
6 Body: gettext.Gettext("Make sure the storage device is correctly formated"),
7 }
8+
9+ msgStorageRemoved message = message{
10+ // TRANSLATORS: This is the summary of a notification bubble with a short message of
11+ // a storage device being removed
12+ Summary: gettext.Gettext("Storage device has been removed"),
13+ // TRANSLATORS: This is the body of a notification bubble with a short message about content
14+ // from the removed device no longer being available
15+ Body: gettext.Gettext("Content previously available on this device will no longer be accessible"),
16+ }
17 )
18
19 var (
20@@ -81,15 +90,22 @@
21 n := notifications.NewNotificationHandler(sessionBus, "ciborium", "system-settings", timeout)
22
23 go func() {
24- for a := range udisks2.DriveAdded {
25- if mountpoint, err := a.Mount(systemBus); err != nil {
26- log.Println("Cannot mount", a.Path, "due to:", err)
27- if err := n.SimpleNotify(msgStorageFail.Summary, msgStorageFail.Body); err != nil {
28- log.Println(err)
29+ for {
30+ select {
31+ case a := <-udisks2.DriveAdded:
32+ if mountpoint, err := a.Mount(systemBus); err != nil {
33+ log.Println("Cannot mount", a.Path, "due to:", err)
34+ if err := n.SimpleNotify(msgStorageFail.Summary, msgStorageFail.Body); err != nil {
35+ log.Println(err)
36+ }
37+ } else {
38+ log.Println("Mounted", a.Path, "as", mountpoint)
39+ if err := n.SimpleNotify(msgStorageSucces.Summary, msgStorageSucces.Body); err != nil {
40+ log.Println(err)
41+ }
42 }
43- } else {
44- log.Println("Mounted", a.Path, "as", mountpoint)
45- if err := n.SimpleNotify(msgStorageSucces.Summary, msgStorageSucces.Body); err != nil {
46+ case <-udisks2.DriveRemoved:
47+ if err := n.SimpleNotify(msgStorageRemoved.Summary, msgStorageRemoved.Body); err != nil {
48 log.Println(err)
49 }
50 }
51
52=== modified file 'po/ciborium.pot'
53--- po/ciborium.pot 2014-08-06 17:40:12 +0000
54+++ po/ciborium.pot 2014-08-13 02:40:31 +0000
55@@ -8,7 +8,7 @@
56 msgstr ""
57 "Project-Id-Version: ciborium\n"
58 "Report-Msgid-Bugs-To: \n"
59-"POT-Creation-Date: 2014-08-06 14:40-0300\n"
60+"POT-Creation-Date: 2014-08-12 23:31-0300\n"
61 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
62 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
63 "Language-Team: LANGUAGE <LL@li.org>\n"
64@@ -19,24 +19,37 @@
65
66 #. TRANSLATORS: This is the summary of a notification bubble with a short message of
67 #. success when addding a storage device.
68-#: cmd/ciborium/main.go:45
69+#: cmd/ciborium/main.go:47
70 msgid "Storage device detected"
71 msgstr ""
72
73 #. TRANSLATORS: This is the body of a notification bubble with a short message about content
74 #. being scanned when addding a storage device.
75-#: cmd/ciborium/main.go:48
76+#: cmd/ciborium/main.go:50
77 msgid "This device will be scanned for new content"
78 msgstr ""
79
80 #. TRANSLATORS: This is the summary of a notification bubble with a short message of
81 #. failure when adding a storage device.
82-#: cmd/ciborium/main.go:54
83+#: cmd/ciborium/main.go:56
84 msgid "Failed to add storage device"
85 msgstr ""
86
87 #. TRANSLATORS: This is the body of a notification bubble with a short message with hints
88 #. with regards to the failure when adding a storage device.
89-#: cmd/ciborium/main.go:57
90+#: cmd/ciborium/main.go:59
91 msgid "Make sure the storage device is correctly formated"
92 msgstr ""
93+
94+#. TRANSLATORS: This is the summary of a notification bubble with a short message of
95+#. a storage device being removed
96+#: cmd/ciborium/main.go:65
97+msgid "Storage device has been removed"
98+msgstr ""
99+
100+#. TRANSLATORS: This is the body of a notification bubble with a short message about content
101+#. from the removed device no longer being available
102+#: cmd/ciborium/main.go:68
103+msgid ""
104+"Content previously available on this device will no longer be accessible"
105+msgstr ""
106
107=== modified file 'udisks2/udisks2.go'
108--- udisks2/udisks2.go 2014-08-13 02:40:31 +0000
109+++ udisks2/udisks2.go 2014-08-13 02:40:31 +0000
110@@ -41,6 +41,7 @@
111
112 type VariantMap map[string]dbus.Variant
113 type InterfacesAndProperties map[string]VariantMap
114+type Interfaces []string
115
116 type Storage struct {
117 Path dbus.ObjectPath
118@@ -50,11 +51,13 @@
119 type driveMap map[dbus.ObjectPath]InterfacesAndProperties
120
121 type UDisks2 struct {
122- conn *dbus.Connection
123- validFS sort.StringSlice
124- DriveAdded chan *Storage
125- driveAdded *dbus.SignalWatch
126- drives driveMap
127+ conn *dbus.Connection
128+ validFS sort.StringSlice
129+ DriveAdded chan *Storage
130+ driveAdded *dbus.SignalWatch
131+ DriveRemoved chan dbus.ObjectPath
132+ driveRemoved *dbus.SignalWatch
133+ drives driveMap
134 }
135
136 func (u *UDisks2) connectToSignal(path dbus.ObjectPath, inter, member string) (*dbus.SignalWatch, error) {
137@@ -71,20 +74,44 @@
138 return u.connectToSignal(dbusObject, dbusObjectManagerInterface, dbusAddedSignal)
139 }
140
141-func (u *UDisks2) initInterfacesAddedChan() {
142+func (u *UDisks2) connectToSignalInterfacesRemoved() (*dbus.SignalWatch, error) {
143+ return u.connectToSignal(dbusObject, dbusObjectManagerInterface, dbusRemovedSignal)
144+}
145+
146+func (u *UDisks2) initInterfacesWatchChan() {
147 go func() {
148- for msg := range u.driveAdded.C {
149- var addedEvent Storage
150- if err := msg.Args(&addedEvent.Path, &addedEvent.Props); err != nil {
151- log.Print(err)
152- continue
153- }
154- if addedEvent.desiredEvent(u.validFS) {
155- u.DriveAdded <- &addedEvent
156+ defer close(u.DriveAdded)
157+ defer close(u.DriveRemoved)
158+ for {
159+ select {
160+ case msg := <-u.driveAdded.C:
161+ var event Storage
162+ if err := msg.Args(&event.Path, &event.Props); err != nil {
163+ log.Print(err)
164+ continue
165+ }
166+ if event.desiredAddEvent(u.validFS) {
167+ u.drives[event.Path] = event.Props
168+ u.DriveAdded <- &event
169+ }
170+ case msg := <-u.driveRemoved.C:
171+ var objectPath dbus.ObjectPath
172+ var interfaces Interfaces
173+ if err := msg.Args(&objectPath, &interfaces); err != nil {
174+ log.Print(err)
175+ continue
176+ }
177+ if _, ok := u.drives[objectPath]; !ok {
178+ log.Println("not concerned about event for", objectPath)
179+ continue
180+ }
181+ if interfaces.desiredRemoveEvent() {
182+ delete(u.drives, objectPath)
183+ u.DriveRemoved <- objectPath
184+ }
185 }
186 }
187 log.Print("Shutting down InterfacesAdded channel")
188- close(u.DriveAdded)
189 }()
190
191 u.emitExistingDevices()
192@@ -104,7 +131,7 @@
193
194 for objectPath, props := range allDevices {
195 s := Storage{objectPath, props}
196- if s.desiredEvent(u.validFS) {
197+ if s.desiredAddEvent(u.validFS) {
198 u.DriveAdded <- &s
199 }
200 }
201@@ -112,28 +139,43 @@
202
203 func NewStorageWatcher(conn *dbus.Connection, filesystems ...string) (u *UDisks2) {
204 u = &UDisks2{
205- conn: conn,
206- validFS: sort.StringSlice(filesystems),
207- DriveAdded: make(chan *Storage),
208+ conn: conn,
209+ validFS: sort.StringSlice(filesystems),
210+ DriveAdded: make(chan *Storage),
211+ DriveRemoved: make(chan dbus.ObjectPath),
212+ drives: make(driveMap),
213 }
214 runtime.SetFinalizer(u, cleanDriveWatch)
215 return u
216 }
217
218 func cleanDriveWatch(u *UDisks2) {
219- log.Print("Cancelling InterfacesAdded signal watch")
220+ log.Print("Cancelling Interfaces signal watch")
221 u.driveAdded.Cancel()
222+ u.driveRemoved.Cancel()
223 }
224
225 func (u *UDisks2) Init() (err error) {
226 if u.driveAdded, err = u.connectToSignalInterfacesAdded(); err != nil {
227 return err
228 }
229- u.initInterfacesAddedChan()
230+ if u.driveRemoved, err = u.connectToSignalInterfacesRemoved(); err != nil {
231+ return err
232+ }
233+ u.initInterfacesWatchChan()
234 return nil
235 }
236
237-func (s *Storage) desiredEvent(validFS sort.StringSlice) bool {
238+func (iface Interfaces) desiredRemoveEvent() bool {
239+ for i := range iface {
240+ if iface[i] == dbusFilesystemInterface {
241+ return true
242+ }
243+ }
244+ return false
245+}
246+
247+func (s *Storage) desiredAddEvent(validFS sort.StringSlice) bool {
248 propFS, ok := s.Props[dbusFilesystemInterface]
249 if !ok {
250 return false

Subscribers

People subscribed via source and target branches