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
=== added file 'cmd/ciborium/dir_test.go'
--- cmd/ciborium/dir_test.go 1970-01-01 00:00:00 +0000
+++ cmd/ciborium/dir_test.go 2014-12-01 13:10:22 +0000
@@ -0,0 +1,108 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Sergio Schvezov: sergio.schvezov@canonical.com
6 *
7 * This file is part of ubuntu-emulator.
8 *
9 * ciborium is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * ubuntu-emulator is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22package main
23
24import (
25 "os"
26 "path/filepath"
27 "testing"
28
29 . "launchpad.net/gocheck"
30)
31
32var _ = Suite(&StandardDirsTestSuite{})
33
34type StandardDirsTestSuite struct {
35 tmpDir string
36}
37
38func (s *StandardDirsTestSuite) SetUpTest(c *C) {
39 s.tmpDir = c.MkDir()
40}
41
42func Test(t *testing.T) { TestingT(t) }
43
44func (s *StandardDirsTestSuite) TestCreateFromScratch(c *C) {
45 createStandardHomeDirs(s.tmpDir)
46
47 for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
48 fi, err := os.Stat(filepath.Join(s.tmpDir, d))
49 c.Assert(err, IsNil)
50 c.Assert(fi.IsDir(), Equals, true)
51 }
52}
53
54func (s *StandardDirsTestSuite) TestCreateWithPreExistingHead(c *C) {
55 c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Documents"), 0755), IsNil)
56 c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Downloads"), 0755), IsNil)
57
58 c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
59
60 for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
61 fi, err := os.Stat(filepath.Join(s.tmpDir, d))
62 c.Assert(err, IsNil)
63 c.Assert(fi.IsDir(), Equals, true)
64 }
65}
66
67func (s *StandardDirsTestSuite) TestCreateWithPreExistingTail(c *C) {
68 c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Videos"), 0755), IsNil)
69
70 c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
71
72 for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
73 fi, err := os.Stat(filepath.Join(s.tmpDir, d))
74 c.Assert(err, IsNil)
75 c.Assert(fi.IsDir(), Equals, true)
76 }
77}
78
79func (s *StandardDirsTestSuite) TestCreateWithPreExistingMiddle(c *C) {
80 c.Assert(os.Mkdir(filepath.Join(s.tmpDir, "Music"), 0755), IsNil)
81
82 c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
83
84 for _, d := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
85 fi, err := os.Stat(filepath.Join(s.tmpDir, d))
86 c.Assert(err, IsNil)
87 c.Assert(fi.IsDir(), Equals, true)
88 }
89}
90
91func (s *StandardDirsTestSuite) TestCreateWithPreExistingNonDir(c *C) {
92 musicFile := filepath.Join(s.tmpDir, "Music")
93 f, err := os.Create(musicFile)
94 c.Assert(err, IsNil)
95 f.Close()
96
97 c.Assert(createStandardHomeDirs(s.tmpDir), IsNil)
98
99 fi, err := os.Stat(musicFile)
100 c.Assert(err, IsNil)
101 c.Assert(fi.IsDir(), Equals, false)
102
103 for _, d := range []string{"Documents", "Downloads", "Pictures", "Videos"} {
104 fi, err := os.Stat(filepath.Join(s.tmpDir, d))
105 c.Assert(err, IsNil)
106 c.Assert(fi.IsDir(), Equals, true)
107 }
108}
0109
=== modified file 'cmd/ciborium/main.go'
--- cmd/ciborium/main.go 2014-09-24 23:02:18 +0000
+++ cmd/ciborium/main.go 2014-12-01 13:10:22 +0000
@@ -23,6 +23,8 @@
23 "errors"23 "errors"
24 "fmt"24 "fmt"
25 "log"25 "log"
26 "os"
27 "path/filepath"
26 "strings"28 "strings"
27 "sync"29 "sync"
28 "syscall"30 "syscall"
@@ -183,6 +185,11 @@
183 msgStorageSuccess.Body,185 msgStorageSuccess.Body,
184 sdCardIcon,186 sdCardIcon,
185 )187 )
188
189 if err := createStandardHomeDirs(m); err != nil {
190 log.Println("Failed to create standard dir layout:", err)
191 }
192
186 mw.set(mountpoint(m), true)193 mw.set(mountpoint(m), true)
187 }194 }
188 case e := <-blockError:195 case e := <-blockError:
@@ -224,6 +231,24 @@
224 <-done231 <-done
225}232}
226233
234// createStandardHomeDirs creates directories reflecting a standard home, these
235// directories are Documents, Downloads, Music, Pictures and Videos
236func createStandardHomeDirs(mountpoint string) error {
237 for _, node := range []string{"Documents", "Downloads", "Music", "Pictures", "Videos"} {
238 dir := filepath.Join(mountpoint, node)
239
240 if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
241 if err := os.MkdirAll(dir, 755); err != nil {
242 return err
243 }
244 } else if err != nil {
245 return err
246 }
247 }
248
249 return nil
250}
251
227// notify only notifies if a notification is actually needed252// notify only notifies if a notification is actually needed
228// depending on freeThreshold and on warningSent's status253// depending on freeThreshold and on warningSent's status
229func buildFreeNotify(nh *notifications.NotificationHandler) notifyFreeFunc {254func buildFreeNotify(nh *notifications.NotificationHandler) notifyFreeFunc {
230255
=== modified file 'debian/control'
--- debian/control 2014-09-02 07:01:27 +0000
+++ debian/control 2014-12-01 13:10:22 +0000
@@ -9,6 +9,7 @@
9 golang-go,9 golang-go,
10 golang-go-dbus-dev,10 golang-go-dbus-dev,
11 golang-go-xdg-dev,11 golang-go-xdg-dev,
12 golang-gocheck-dev,
12 libqt5opengl5-dev,13 libqt5opengl5-dev,
13 pkg-config,14 pkg-config,
14 qtbase5-private-dev,15 qtbase5-private-dev,

Subscribers

People subscribed via source and target branches