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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 87
Merged at revision: 83
Proposed branch: lp:~sergiusens/ciborium/mediadirs
Merge into: lp:ciborium
Diff against target: 174 lines (+134/-0)
3 files modified
cmd/ciborium/dir_test.go (+108/-0)
cmd/ciborium/main.go (+25/-0)
debian/control (+1/-0)
To merge this branch: bzr merge lp:~sergiusens/ciborium/mediadirs
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ricardo Salveti (community) Approve
Manuel de la Peña (community) Approve
Florian Boucault Pending
Review via email: mp+242838@code.launchpad.net

Commit message

Create standard home dirs (Documents, Downloads, Music, Pictures and Videos) after mounting, if they don't exist

Description of the change

This silently creates Pictures and Videos if it doesn't exist on the mountpoint. This may not be desktop friendly.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Don't we need to do this respecting the current language of the system? We might also need to create some additional dirs, such as Documents and Downloads. Might want to check how that is done on the desktop, and do a similar thing for touch (sdcard).

review: Needs Information
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

From IRC, let's make sure we're creating the following dirs: Music, Pictures, Videos, Downloads and Documents.

review: Needs Fixing
lp:~sergiusens/ciborium/mediadirs updated
84. By Sergio Schvezov

Creating all the standard dirs

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

updated.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) :
review: Needs Fixing
lp:~sergiusens/ciborium/mediadirs updated
85. By Sergio Schvezov

Changing naming and comments

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Florian Boucault (fboucault) wrote :

> Don't we need to do this respecting the current language of the system? We
> might also need to create some additional dirs, such as Documents and
> Downloads. Might want to check how that is done on the desktop, and do a
> similar thing for touch (sdcard).

I asked that question to jdstrand and he said that the apparmor profiles would not accomodate with variable paths hence the names had to remain always the same regardless of language.

Revision history for this message
Florian Boucault (fboucault) wrote :

> Don't we need to do this respecting the current language of the system? We
> might also need to create some additional dirs, such as Documents and
> Downloads. Might want to check how that is done on the desktop, and do a
> similar thing for touch (sdcard).

I asked that question to jdstrand and he said that the apparmor profiles would not accomodate with variable paths hence the names had to remain always the same regardless of language.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Comments inline.

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) :
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
Ricardo Salveti (rsalveti) :
review: Needs Fixing
lp:~sergiusens/ciborium/mediadirs updated
86. By Sergio Schvezov

Don't return if err == nil

Revision history for this message
Sergio Schvezov (sergiusens) :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~sergiusens/ciborium/mediadirs updated
87. By Sergio Schvezov

Added unit tests

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

LGTM, worked fine now.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'cmd/ciborium/dir_test.go'
2--- cmd/ciborium/dir_test.go 1970-01-01 00:00:00 +0000
3+++ cmd/ciborium/dir_test.go 2014-12-01 13:10:22 +0000
4@@ -0,0 +1,108 @@
5+/*
6+ * Copyright 2014 Canonical Ltd.
7+ *
8+ * Authors:
9+ * Sergio Schvezov: sergio.schvezov@canonical.com
10+ *
11+ * This file is part of ubuntu-emulator.
12+ *
13+ * ciborium is free software; you can redistribute it and/or modify
14+ * it under the terms of the GNU General Public License as published by
15+ * the Free Software Foundation; version 3.
16+ *
17+ * ubuntu-emulator is distributed in the hope that it will be useful,
18+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+ * GNU General Public License for more details.
21+ *
22+ * You should have received a copy of the GNU General Public License
23+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
24+ */
25+
26+package main
27+
28+import (
29+ "os"
30+ "path/filepath"
31+ "testing"
32+
33+ . "launchpad.net/gocheck"
34+)
35+
36+var _ = Suite(&StandardDirsTestSuite{})
37+
38+type StandardDirsTestSuite struct {
39+ tmpDir string
40+}
41+
42+func (s *StandardDirsTestSuite) SetUpTest(c *C) {
43+ s.tmpDir = c.MkDir()
44+}
45+
46+func Test(t *testing.T) { TestingT(t) }
47+
48+func (s *StandardDirsTestSuite) TestCreateFromScratch(c *C) {
49+ createStandardHomeDirs(s.tmpDir)
50+
51+ for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
52+ fi, err := os.Stat(filepath.Join(s.tmpDir, d))
53+ c.Assert(err, IsNil)
54+ c.Assert(fi.IsDir(), Equals, true)
55+ }
56+}
57+
58+func (s *StandardDirsTestSuite) TestCreateWithPreExistingHead(c *C) {
59+ c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Documents"), 0755), IsNil)
60+ c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Downloads"), 0755), IsNil)
61+
62+ c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
63+
64+ for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
65+ fi, err := os.Stat(filepath.Join(s.tmpDir, d))
66+ c.Assert(err, IsNil)
67+ c.Assert(fi.IsDir(), Equals, true)
68+ }
69+}
70+
71+func (s *StandardDirsTestSuite) TestCreateWithPreExistingTail(c *C) {
72+ c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Videos"), 0755), IsNil)
73+
74+ c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
75+
76+ for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
77+ fi, err := os.Stat(filepath.Join(s.tmpDir, d))
78+ c.Assert(err, IsNil)
79+ c.Assert(fi.IsDir(), Equals, true)
80+ }
81+}
82+
83+func (s *StandardDirsTestSuite) TestCreateWithPreExistingMiddle(c *C) {
84+ c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Music"), 0755), IsNil)
85+
86+ c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
87+
88+ for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
89+ fi, err := os.Stat(filepath.Join(s.tmpDir, d))
90+ c.Assert(err, IsNil)
91+ c.Assert(fi.IsDir(), Equals, true)
92+ }
93+}
94+
95+func (s *StandardDirsTestSuite) TestCreateWithPreExistingNonDir(c *C) {
96+ musicFile := filepath.Join(s.tmpDir, "Music")
97+ f, err := os.Create(musicFile)
98+ c.Assert(err, IsNil)
99+ f.Close()
100+
101+ c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
102+
103+ fi, err := os.Stat(musicFile)
104+ c.Assert(err, IsNil)
105+ c.Assert(fi.IsDir(), Equals, false)
106+
107+ for _, d := range []string{"Documents", "Downloads", "Pictures", "Videos"} {
108+ fi, err := os.Stat(filepath.Join(s.tmpDir, d))
109+ c.Assert(err, IsNil)
110+ c.Assert(fi.IsDir(), Equals, true)
111+ }
112+}
113
114=== modified file 'cmd/ciborium/main.go'
115--- cmd/ciborium/main.go 2014-09-24 23:02:18 +0000
116+++ cmd/ciborium/main.go 2014-12-01 13:10:22 +0000
117@@ -23,6 +23,8 @@
118 "errors"
119 "fmt"
120 "log"
121+ "os"
122+ "path/filepath"
123 "strings"
124 "sync"
125 "syscall"
126@@ -183,6 +185,11 @@
127 msgStorageSuccess.Body,
128 sdCardIcon,
129 )
130+
131+ if err := createStandardHomeDirs(m); err != nil {
132+ log.Println("Failed to create standard dir layout:", err)
133+ }
134+
135 mw.set(mountpoint(m), true)
136 }
137 case e := <-blockError:
138@@ -224,6 +231,24 @@
139 <-done
140 }
141
142+// createStandardHomeDirs creates directories reflecting a standard home, these
143+// directories are Documents, Downloads, Music, Pictures and Videos
144+func createStandardHomeDirs(mountpoint string) error {
145+ for _, node := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
146+ dir := filepath.Join(mountpoint, node)
147+
148+ if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
149+ if err := os.MkdirAll(dir, 755); err != nil {
150+ return err
151+ }
152+ } else if err != nil {
153+ return err
154+ }
155+ }
156+
157+ return nil
158+}
159+
160 // notify only notifies if a notification is actually needed
161 // depending on freeThreshold and on warningSent's status
162 func buildFreeNotify(nh *notifications.NotificationHandler) notifyFreeFunc {
163
164=== modified file 'debian/control'
165--- debian/control 2014-09-02 07:01:27 +0000
166+++ debian/control 2014-12-01 13:10:22 +0000
167@@ -9,6 +9,7 @@
168 golang-go,
169 golang-go-dbus-dev,
170 golang-go-xdg-dev,
171+ golang-gocheck-dev,
172 libqt5opengl5-dev,
173 pkg-config,
174 qtbase5-private-dev,

Subscribers

People subscribed via source and target branches