reworking database, init and add commands
This commit is contained in:
@@ -3,34 +3,9 @@ package database
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
"github.com/asdine/storm/q"
|
||||
)
|
||||
|
||||
// ConfigureDB sets up bolt and Storm according to the path of the database
|
||||
// this is done here so that different databases can be configured in different scenarios
|
||||
func (db *DB) ConfigureDB(dbPath string) error {
|
||||
var err error
|
||||
if db.DB, err = storm.Open(dbPath); err != nil {
|
||||
return err
|
||||
}
|
||||
var file File
|
||||
if err := db.One("Name", "-- All Files --", &file); err != nil {
|
||||
if err.Error() != "not found" {
|
||||
db.Err(err).Msg("Error finding file by path")
|
||||
return err
|
||||
}
|
||||
db.Warn().Msg("No existing databse found. initialising new database")
|
||||
file.Name = "-- All Files --"
|
||||
//file.Ignore = true //this is currently not used however could result in this file being ignored when file watching (etc) starts
|
||||
if err := db.Save(&file); err != nil {
|
||||
db.Err(err).Msg("Error storing the diff")
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckIfFileCurrentlyMonitored checks if the file is already being monitored. This is a read-only check
|
||||
// to see whether the file was correctly initialised
|
||||
// (BUG) The hash causes the same file to be in database multiple times!
|
||||
@@ -55,10 +30,12 @@ func (db *DB) CheckIfFileCurrentlyMonitored(path string) bool {
|
||||
// This can be used to trigger the same files to be watched again
|
||||
func (db *DB) RetrieveTrackedFiles() ([]File, error) {
|
||||
var files []File
|
||||
fmt.Println("Starting file extraction")
|
||||
if err := db.All(&files); err != nil {
|
||||
db.Err(err).Msg("Error retrieving all watched files")
|
||||
return []File{}, err
|
||||
}
|
||||
fmt.Println("Ending file extraction")
|
||||
return files, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user