working on adding files to repo and making sure no duplicates

This commit is contained in:
2020-06-19 22:57:42 -04:00
parent e75991da22
commit 47cc65a824
7 changed files with 113 additions and 67 deletions

View File

@@ -1,6 +0,0 @@
{"level":"warn","module":"database","message":"No existing databse found. initialising new database"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"The file was [not found], so continuing to create it in the database"}
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u0001{\ufffd[Ȼ[8\ufffdR!\ufffd\ufffdB at time: %!s(func() string=0x68c5b0)"}

View File

@@ -0,0 +1,26 @@
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u0001{\ufffd[Ȼ[8\ufffdR!\ufffd\ufffdB at time: %!s(func() string=0x68c530)"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u0001{\ufffd[Ȼ[8\ufffdR!\ufffd\ufffdB at time: %!s(func() string=0x68c6a0)"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u0001{\ufffd[Ȼ[8\ufffdR!\ufffd\ufffdB at time: %!s(func() string=0x68c6a0)"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}

View File

@@ -46,10 +46,15 @@ func main() {
os.Exit(0)
}
fmt.Println("Attempting to start logger...")
// Setting up the logger to file output
logFile, err := os.OpenFile(".gvc/gvclog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
// Checking the .gvc structure
dirPaths, err := manager.CheckPaths(rootPath)
if err != nil {
log.Fatalf("unable to open log file at: %s, exiting with error: %s", ".gvc/gvclog.log", err)
log.Fatalf("unable to create/verify .gvc folder structure: %s", err)
}
// Setting up the logger to file output
logFile, err := os.OpenFile(".gvc/logs/gvclog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("unable to open log file at: %s, exiting with error: %s", ".gvc/logs/gvclog.log", err)
}
defer logFile.Close()
// Setup non-http logging (using middleware for Echo http logging)
@@ -65,7 +70,7 @@ func main() {
// clientlog.Fatal().Msgf("Unable to open or create a database in the .gvc folder, fatal")
//}
informer := make(chan manager.OperatingMessage)
m, err = manager.NewManager(rootPath, version, ".gvc/gvc.db", informer, &clientlog)
m, err = manager.NewManager(rootPath, version, ".gvc/gvc.db", informer, dirPaths, &clientlog)
if err != nil {
clientlog.Fatal().Msgf("unable to create new manager object... %s", err)
}

View File

@@ -1,6 +1,7 @@
package clientcmd
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -21,6 +22,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return err
}
var trackedFiles []string
var SkipDir = errors.New("ignore folder, either .gvc or on ignores") // default variable for filewalk errors to skip the entire dir
switch inputType {
case "file": // If the -file flag was used, then make sure it is a file, make sure not on ignore list, then add it to tracked files
_, err := os.Stat(input)
@@ -39,6 +41,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
// }
// }
relativePath := input //TODO: Figure out if path is corrrect?
fmt.Println("Relative Path: ", relativePath)
err = m.AddFileToRepo(relativePath)
if err != nil {
return fmt.Errorf("unable to add file to repo: %s", err)
@@ -59,13 +62,19 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
if currentFile == ".gvc" { // can't track anything in .gvc
return SkipDir
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
if err != nil {
return SkipDir
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
}
}
fmt.Println("adding file: ", path)
relativePath, err := filepath.Rel(workingDir, path)
@@ -92,17 +101,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
}
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path) // Stripping all the pathing so we just get the filename
fmt.Println("path: ", path)
fmt.Printf("Checking file: %s\n", currentFile)
if err != nil {
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
if currentFile == ".gvc" { // can't track anything in .gvc
return nil
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
if err != nil {
return err
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
}
}
fileExt := filepath.Ext(path)
if fileExt == wildcard { // seeing if the file ext matches the wildcard
@@ -111,6 +128,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
if err != nil {
return fmt.Errorf("unable to create relative path for file: %s", err)
}
fmt.Println("WILDCARD Relative Path: ", relativePath)
err = m.AddFileToRepo(relativePath)
if err != nil {
return fmt.Errorf("unable to add file to repo: %s", err)
@@ -126,13 +144,19 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
if currentFile == ".gvc" { // can't track anything in .gvc
return SkipDir
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
if err != nil {
return SkipDir
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
return nil
}
}
relativePath, err := filepath.Rel(workingDir, path)
if err != nil {

View File

@@ -13,6 +13,9 @@ import (
var ConfigPath string
func validateFileType(path string, inputType string) error {
if inputType == "wildcard" { // Can't stat wildcard type
return nil
}
fullPath, err := filepath.Abs(path)
if err != nil {
return fmt.Errorf("cannot stat file, invalid input? %s", err)