Skip to content

Commit

Permalink
Fixed bug with database creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
oniony committed Feb 9, 2015
1 parent fc51a31 commit 8f334ef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ Sqlite3 libraries, their Go bindings and the Go language standard library.
Release Notes
=============

v0.5.1
------

* Fixed bug with database initialization when .tmsu directory does not
already exist.

v0.5.0
------

Expand Down
6 changes: 0 additions & 6 deletions src/tmsu/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ func initExec(store *storage.Storage, options Options, args []string) error {
func initializeDatabase(path string) error {
tmsuPath := filepath.Join(path, ".tmsu")

if err := os.Mkdir(tmsuPath, 0755); err != nil {
if !os.IsExist(err) {
return fmt.Errorf("could not create .tmsu directory: %v", err)
}
}

dbPath := filepath.Join(tmsuPath, "db")

store, err := storage.OpenAt(dbPath)
Expand Down
5 changes: 5 additions & 0 deletions src/tmsu/cli/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func (parser *OptionParser) Parse(args ...string) (commandName string, options O
if len(parts) == 2 {
option.Argument = parts[1]
} else {
if len(args) < index+2 {
err = fmt.Errorf("missing argument for option '%v'", optionName)
return
}

option.Argument = args[index+1]
index++
}
Expand Down
4 changes: 4 additions & 0 deletions src/tmsu/storage/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
_ "github.com/mattn/go-sqlite3"
"os"
"path/filepath"
"tmsu/common/log"
)

Expand All @@ -40,6 +41,9 @@ func OpenAt(path string) (*Database, error) {
if err != nil {
if os.IsNotExist(err) {
log.Warnf("creating database at '%v'.", path)

dir := filepath.Dir(path)
os.Mkdir(dir, 0755)
} else {
log.Warnf("could not stat database: %v", err)
}
Expand Down

0 comments on commit 8f334ef

Please sign in to comment.