fixing bug with config generation, started fixing add command, next commit command

This commit is contained in:
2020-07-04 22:05:02 -04:00
parent 5af55ed62e
commit c07e09d155
10 changed files with 256 additions and 44 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/rs/zerolog"
)
// OpenDB returns a new database object, from opening existing db
// OpenDB returns a new database object, from opening existing db //TODO, figure out when to close this
func OpenDB(dbPath string, log *zerolog.Logger, version string) (*DB, error) {
var db DB
var err error
@@ -20,7 +20,7 @@ func OpenDB(dbPath string, log *zerolog.Logger, version string) (*DB, error) {
db.Err(err).Msg("No existing database found. this does not appear to be a repo, please init repo")
return &db, err
}
defer db.Close()
//defer db.Close()
return &db, nil
}

View File

@@ -15,11 +15,11 @@ func (db *DB) CheckIfFileCurrentlyMonitored(path string) bool {
if err := db.One("Path", path, &file); err != nil {
if err.Error() != "not found" {
db.Err(err).Msg("Error finding file by path")
fmt.Printf("Not found: %s error: %s\n", path, err)
fmt.Printf("Database Error occurred: %s error: %s\n", path, err)
return false
}
db.Warn().Msg("no file found")
fmt.Printf("Not found: %s error: %s\n", path, err)
db.Warn().Msgf("%s not found in tracked database", path)
fmt.Printf("%s not found in tracked file database", path)
return false
}
fmt.Printf("Found!: %s searched: %s\n", file.Path, path)

View File

@@ -68,28 +68,6 @@ func ExpandToIntArray(length int64, arry []byte, intArray *[]int64) error {
// return fileName, nil
// }
//InitiateDirectory checks all of the directories to make sure they exist
func InitiateDirectory(directory string) {
// For the keys-folder we need to check if the folder exists...
checkDir, err := IsDirectory(directory)
if err != nil {
fmt.Println("Error checking for "+directory+" directory: %s\r\n", err)
panic(err)
}
if checkDir == true {
fmt.Println(directory + " already exists")
} else {
// Create the directory.
fmt.Println("Creating " + directory)
err = CreateDirectory(directory)
if err != nil {
fmt.Println("Error creating the folder %s\r\n", err)
panic(err)
}
}
}
func ConvertFileForStorage(file *database.File, folder string) error {
fileBytes, err := ioutil.ReadFile(file.Path)
if err != nil {

View File

@@ -46,6 +46,7 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope
informer,
dirPaths,
}
return &m, nil
}
@@ -112,13 +113,13 @@ func CreatePaths(rootDir string) error {
if err != nil {
return fmt.Errorf("unable to generate file paths.. %s", err)
}
InitiateDirectory(fullFilePaths.KeyFolder)
InitiateDirectory(fullFilePaths.DownloadFolder)
InitiateDirectory(fullFilePaths.SyncFolder)
InitiateDirectory(fullFilePaths.ObjectFolder)
InitiateDirectory(fullFilePaths.ThumbFolder)
InitiateDirectory(fullFilePaths.LogFolder)
InitiateDirectory(fullFilePaths.PluginFolder)
CreateDirectory(fullFilePaths.KeyFolder)
CreateDirectory(fullFilePaths.DownloadFolder)
CreateDirectory(fullFilePaths.SyncFolder)
CreateDirectory(fullFilePaths.ObjectFolder)
CreateDirectory(fullFilePaths.ThumbFolder)
CreateDirectory(fullFilePaths.LogFolder)
CreateDirectory(fullFilePaths.PluginFolder)
return nil
}
@@ -160,6 +161,7 @@ func (m *Manager) AddFileToRepo(relFilePath string) error {
if hash, err = UniqueFileHash(relFilePath); err != nil {
return err
}
m.Info().Msgf("Hash generated for file: %s hash: %s", relFilePath, hex.EncodeToString(hash))
alreadyTracked := m.dB.CheckIfFileCurrentlyMonitored(relFilePath)
if alreadyTracked {
return fmt.Errorf("file already found in tracked files, not adding: %s", relFilePath)