diff options
| author | Michael Vogt <mvo@ubuntu.com> | 2016-02-12 15:24:45 +0100 |
|---|---|---|
| committer | Michael Vogt <mvo@ubuntu.com> | 2016-02-12 15:24:45 +0100 |
| commit | 22ba43797492444fad8684aeabbf43c61068064e (patch) | |
| tree | 5aa9861d753310c7d88d74c749a5c535a5e323ec | |
| parent | 6c4bb71c3743eb0a284f07bd8c044bd28a6707e3 (diff) | |
Never return nil in NewLocalSnapRepository()bugfix/crash-less
If the directory is not (yet) there do not return nil and cause potential crashes.
| -rw-r--r-- | snappy/snap_local_repo.go | 7 | ||||
| -rw-r--r-- | snappy/snapp_test.go | 8 |
2 files changed, 8 insertions, 7 deletions
diff --git a/snappy/snap_local_repo.go b/snappy/snap_local_repo.go index 02c78f5c77..72c478d586 100644 --- a/snappy/snap_local_repo.go +++ b/snappy/snap_local_repo.go @@ -20,7 +20,6 @@ package snappy import ( - "os" "path/filepath" "github.com/ubuntu-core/snappy/dirs" @@ -39,11 +38,9 @@ type SnapLocalRepository struct { // NewLocalSnapRepository returns a new SnapLocalRepository for the given // path func NewLocalSnapRepository() *SnapLocalRepository { - path := dirs.SnapSnapsDir - if s, err := os.Stat(path); err != nil || !s.IsDir() { - return nil + return &SnapLocalRepository{ + path: dirs.SnapSnapsDir, } - return &SnapLocalRepository{path: path} } // Installed returns the installed snaps from this repository diff --git a/snappy/snapp_test.go b/snappy/snapp_test.go index f6b23ef61a..e12b79e2bf 100644 --- a/snappy/snapp_test.go +++ b/snappy/snapp_test.go @@ -171,10 +171,14 @@ frameworks: c.Check(fmk, DeepEquals, []string{"one", "two"}) } -func (s *SnapTestSuite) TestLocalSnapRepositoryInvalid(c *C) { +func (s *SnapTestSuite) TestLocalSnapRepositoryInvalidIsStillOk(c *C) { dirs.SnapSnapsDir = "invalid-path" snap := NewLocalSnapRepository() - c.Assert(snap, IsNil) + c.Assert(snap, NotNil) + + installed, err := snap.Installed() + c.Assert(err, IsNil) + c.Assert(installed, HasLen, 0) } func (s *SnapTestSuite) TestLocalSnapRepositorySimple(c *C) { |
