Merge ~morphis/snappy-hwe-snaps/+git/udisks2:bugs/ciborium/only-thumb-and-removable into ~snappy-hwe-team/snappy-hwe-snaps/+git/udisks2:ciborium/0.2.12

Proposed by Simon Fels
Status: Merged
Approved by: Scott Sweeny
Approved revision: 288072d18cfae802573bdfbcc9e92753811f0bdd
Merged at revision: d421248af0c897340cc17421b670eebdfadc8da9
Proposed branch: ~morphis/snappy-hwe-snaps/+git/udisks2:bugs/ciborium/only-thumb-and-removable
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/udisks2:ciborium/0.2.12
Diff against target: 128 lines (+72/-8)
5 files modified
cmd/ciborium/main.go (+1/-1)
dev/null (+0/-0)
run-tests.sh (+25/-0)
udisks2/udisks2.go (+22/-7)
udisks2/udisks2_test.go (+24/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Konrad Zapałowicz (community) code Approve
Scott Sweeny (community) Approve
Alfonso Sanchez-Beato Approve
Review via email: mp+317847@code.launchpad.net

Description of the change

udisks2: don't mount non-removable and non-thumb devices

We don't want devices which are not marked as removable or as a thumb
drive to be ever selected as candidate for the auto-mounter. The udisks2
API documentation states that some USB storages devices are marked with
MediaRemovable=true even if they don't have any removable media. We need
to make sure that we correctly check both, the MediaRemovable and the
Removable property in our detection logic. In addition to that we then
only want thumb drives to be allowed for the auto-mounter.

This also enables proper CI tests for this branch now that we have capabilities on our CI agent to test things not having spread tests. The tests will build the relevant parts of the source and run available tests.

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

review: Approve
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

ok

review: Approve (code)
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

just a small suggestion

review: Needs Fixing
Revision history for this message
Scott Sweeny (ssweeny) wrote :

LGTM

review: Approve
Revision history for this message
Simon Fels (morphis) :
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

LGTM

review: Approve (code)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.ci_tests_disabled b/.ci_tests_disabled
2deleted file mode 100644
3index e69de29..0000000
4--- a/.ci_tests_disabled
5+++ /dev/null
6diff --git a/cmd/ciborium/main.go b/cmd/ciborium/main.go
7index 53e0cdf..9f891ab 100644
8--- a/cmd/ciborium/main.go
9+++ b/cmd/ciborium/main.go
10@@ -103,7 +103,7 @@ var (
11 func init() {
12 mw = newMountwatch()
13 mw.set(homeMountpoint, true)
14- supportedFS = []string{"vfat"}
15+ supportedFS = []string{"vfat", "ntfs"}
16 }
17
18 func main() {
19diff --git a/run-tests.sh b/run-tests.sh
20new file mode 100755
21index 0000000..9645219
22--- /dev/null
23+++ b/run-tests.sh
24@@ -0,0 +1,25 @@
25+#!/bin/sh -ex
26+
27+SUDO=
28+if [ $(id -u) -ne 0 ]; then
29+ SUDO=sudo
30+fi
31+
32+# Install all necessary build dependencies in our bare build environment
33+$SUDO apt update
34+$SUDO apt install -y --force-yes \
35+ golang-go \
36+ bzr
37+
38+export GOPATH=`mktemp -d`
39+
40+mkdir -p $GOPATH/src/launchpad.net
41+ln -sf $PWD $GOPATH/src/launchpad.net/ciborium
42+
43+go get -v launchpad.net/ciborium/cmd/ciborium
44+go get -v -t launchpad.net/ciborium/cmd/ciborium
45+
46+go build -v launchpad.net/ciborium/cmd/ciborium
47+
48+go test -v launchpad.net/ciborium/cmd/ciborium
49+go test -v launchpad.net/ciborium/udisks2
50diff --git a/udisks2/udisks2.go b/udisks2/udisks2.go
51index d86e22e..a3a9313 100644
52--- a/udisks2/udisks2.go
53+++ b/udisks2/udisks2.go
54@@ -553,6 +553,14 @@ func exists(path string) bool {
55 return true
56 }
57
58+func isAcceptedDevice(mediaRemovable, removable, thumbDrive bool) bool {
59+ // Some USB thumb devices report they have removable media where they
60+ // have not. See udisks2 API documentation for more details.
61+ // In summary we only accept devices which are marked as removable and
62+ // are thumb drivers. Otherwise all devices are not accepted.
63+ return (mediaRemovable || removable) && thumbDrive
64+}
65+
66 func (u *UDisks2) desiredMountableEvent(s *Event) (bool, error) {
67 // Check if automount is enabled for the snap
68 if !exists(os.Getenv("SNAP_COMMON") + "/.automount_enabled") {
69@@ -587,15 +595,22 @@ func (u *UDisks2) desiredMountableEvent(s *Event) (bool, error) {
70 log.Println(drivePath, "doesn't hold a Drive interface")
71 return false, nil
72 }
73- if mediaRemovableVariant, ok := driveProps["MediaRemovable"]; !ok {
74+ removableVariant, ok := driveProps["Removable"]
75+ if !ok {
76+ log.Println(drivePath, "which holds", s.Path, "doesn't have Removable")
77+ return false, nil
78+ }
79+ mediaRemovableVariant, ok := driveProps["MediaRemovable"]
80+ if !ok {
81 log.Println(drivePath, "which holds", s.Path, "doesn't have MediaRemovable")
82 return false, nil
83- } else {
84- mediaRemovable := reflect.ValueOf(mediaRemovableVariant.Value).Bool()
85- if !mediaRemovable && !isThumbDrive(driveProps) {
86- log.Println(drivePath, "which holds", s.Path, "is not MediaRemovable or a thumb drive")
87- return false, nil
88- }
89+ }
90+
91+ removable := reflect.ValueOf(removableVariant.Value).Bool()
92+ mediaRemovable := reflect.ValueOf(mediaRemovableVariant.Value).Bool()
93+ if !isAcceptedDevice(mediaRemovable, removable, isThumbDrive(driveProps)) {
94+ log.Println(drivePath, "which holds", s.Path, "is not Removable or MediaRemovable and a thumb drive")
95+ return false, nil
96 }
97
98 if s.Props.isMounted() {
99diff --git a/udisks2/udisks2_test.go b/udisks2/udisks2_test.go
100new file mode 100644
101index 0000000..9494117
102--- /dev/null
103+++ b/udisks2/udisks2_test.go
104@@ -0,0 +1,24 @@
105+package udisks2
106+
107+import . "launchpad.net/gocheck"
108+
109+type Udisks2TestSuite struct{}
110+
111+var _ = Suite(&Udisks2TestSuite{})
112+
113+func (s *Udisks2TestSuite) TestIsDeviceAcceptedForAutomount(c *C) {
114+ // Device with MediaRemovable = true, Removable = true and MediaCompatibility = []
115+ c.Assert(isAcceptedDevice(true, true, false), Equals, false)
116+ // Device with MediaRemovable = true, Removable = false and MediaCompatibility = []
117+ c.Assert(isAcceptedDevice(true, false, false), Equals, false)
118+ // Device with MediaRemovable = false, Removable = false and MediaCompatibility = []
119+ c.Assert(isAcceptedDevice(false, false, false), Equals, false)
120+ // Device with MediaRemovable = true, Removable = true and MediaCompatibility = [thumb]
121+ c.Assert(isAcceptedDevice(true, true, true), Equals, true)
122+ // Device with MediaRemovable = true, Removable = false and MediaCompatibility = [thumb]
123+ c.Assert(isAcceptedDevice(true, false, true), Equals, true)
124+ // Device with MediaRemovable = false, Removable = true and MediaCompatibility = [thumb]
125+ c.Assert(isAcceptedDevice(false, true, true), Equals, true)
126+ // Device with MediaRemovable = false, Removable = false and MediaCompatibility = [thumb]
127+ c.Assert(isAcceptedDevice(false, false, true), Equals, false)
128+}

Subscribers

People subscribed via source and target branches

to all changes: