starting to write the commit functions

This commit is contained in:
2020-06-20 18:48:58 -04:00
parent 47cc65a824
commit 1ec7b436da
9 changed files with 268 additions and 32 deletions

BIN
client/.gvc/boltbrowser.exe Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -24,3 +24,150 @@
{"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":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: test.go at path: test.go with hash: \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 at time: %!s(func() string=0x68c480)"}
{"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":"unable to add file to repo: file already found in tracked files, not adding: client.go\n"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: client.go\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: add.go at path: clientcmd\\add.go with hash: \ufffd4\ufffd\ufffdb&\ufffd\ufffd\ufffdNR\ufffd\ufffdV\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: branch.go at path: clientcmd\\branch.go with hash: \ufffd\u0006\ufffd\ufffd\ufffd\ufffd[^\u0015M\ufffd\ufffd(Z\ufffdc at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: commonlib.go at path: clientcmd\\commonlib.go with hash: \ufffd\u000fMQ<\ufffd\ufffd\u0016\ufffdM&z\u0010\ufffdw\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: ignore.go at path: clientcmd\\ignore.go with hash: \ufffd!\u0007\ufffd35z\n\ufffdG\b1R\ufffd\ufffdC at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: info.go at path: clientcmd\\info.go with hash: \ufffd\u0007\ufffd3*\ufffd\ufffdD:zX\ufffdѳ\ufffd\u000b at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: init.go at path: clientcmd\\init.go with hash: \ufffd\u0004\ufffd\ufffd6!\ufffd\u0017\ufffd{\ufffdfHH\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: lock.go at path: clientcmd\\lock.go with hash: \ufffd,1\ufffd\ufffd\ufffd\ufffdn\ufffd1\ufffdK+\u0003\ufffd? at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: refresh.go at path: clientcmd\\refresh.go with hash: \ufffd\u0019\ufffd\ufffd\ufffd\ufffdh\ufffd\ufffdzx,\ufffd\ufffd\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: remote.go at path: clientcmd\\remote.go with hash: \ufffd\fh۫\ufffd)D\ufffd\ufffd\ufffdFg\ufffd\ufffd\u0012 at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: switch.go at path: clientcmd\\switch.go with hash: \ufffd\u0004J\u000b\ufffd\ufffd\ufffd?\ufffd\ufffd\ufffdEw\ufffd^Q at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: config.go at path: clientconfig\\config.go with hash: \ufffd\u001bf\ufffdE_\u0017-\ufffd\ufffd\ufffd1\ufffd'<\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: structures.go at path: clientconfig\\structures.go with hash: \ufffd\fc\ufffd\u0000\ufffd\ufffdbs\ufffd\ufffd\ufffdc\r\ufffd\b at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: test.go at path: test\\test.go with hash: \ufffd\u0002\ufffd|\ufffd`\ufffd\ufffd\u0002W\ufffdE\u007fd\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: test.go\n"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory: %!s(<nil>)\n"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: client.go\n"}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: clientcmd\\add.go\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\branch.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\commonlib.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\ignore.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\info.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\init.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\lock.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\refresh.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\remote.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientcmd\\switch.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientconfig\\config.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [clientconfig\\structures.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"error","module":"database","error":"already exists","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [test\\test.go] is monitored. Error already exists"}
{"level":"info","message":"unable to add file to repo: already exists\n"}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: test.go\n"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"Creating new Manager..."}
{"level":"warn","module":"database","message":"No existing databse found. initialising new database"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"skipping .gvc directory"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u00013\ufffdw\ufffd*\ufffd\ufffd\ufffdb?x\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: add.go at path: clientcmd\\add.go with hash: \ufffd8\u0001\\\u001e+\ufffdx}ҟL\ufffd<\ufffdM at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: branch.go at path: clientcmd\\branch.go with hash: \ufffd\u0006\ufffd\ufffd\ufffd\ufffd[^\u0015M\ufffd\ufffd(Z\ufffdc at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: commonlib.go at path: clientcmd\\commonlib.go with hash: \ufffd\u000fMQ<\ufffd\ufffd\u0016\ufffdM&z\u0010\ufffdw\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: ignore.go at path: clientcmd\\ignore.go with hash: \ufffd!\u0007\ufffd35z\n\ufffdG\b1R\ufffd\ufffdC at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: info.go at path: clientcmd\\info.go with hash: \ufffd\u0007\ufffd3*\ufffd\ufffdD:zX\ufffdѳ\ufffd\u000b at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: init.go at path: clientcmd\\init.go with hash: \ufffd\u0004\ufffd\ufffd6!\ufffd\u0017\ufffd{\ufffdfHH\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: lock.go at path: clientcmd\\lock.go with hash: \ufffd,1\ufffd\ufffd\ufffd\ufffdn\ufffd1\ufffdK+\u0003\ufffd? at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: refresh.go at path: clientcmd\\refresh.go with hash: \ufffd\u0019\ufffd\ufffd\ufffd\ufffdh\ufffd\ufffdzx,\ufffd\ufffd\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: remote.go at path: clientcmd\\remote.go with hash: \ufffd\fh۫\ufffd)D\ufffd\ufffd\ufffdFg\ufffd\ufffd\u0012 at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: switch.go at path: clientcmd\\switch.go with hash: \ufffd\u0004J\u000b\ufffd\ufffd\ufffd?\ufffd\ufffd\ufffdEw\ufffd^Q at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: config.go at path: clientconfig\\config.go with hash: \ufffd\u001bf\ufffdE_\u0017-\ufffd\ufffd\ufffd1\ufffd'<\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: structures.go at path: clientconfig\\structures.go with hash: \ufffd\fc\ufffd\u0000\ufffd\ufffdbs\ufffd\ufffd\ufffdc\r\ufffd\b at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: test.go at path: test\\test.go with hash: \ufffd\u0002\ufffd|\ufffd`\ufffd\ufffd\u0002W\ufffdE\u007fd\ufffd\ufffd at time: %!s(func() string=0x68c7c0)"}
{"level":"warn","module":"database","message":"no file found"}
{"level":"info","message":"added file: test.go at path: test.go with hash: \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 at time: %!s(func() string=0x68c7c0)"}
{"level":"info","message":"Adding the following files to tracked: [client.go clientcmd\\add.go clientcmd\\branch.go clientcmd\\commonlib.go clientcmd\\ignore.go clientcmd\\info.go clientcmd\\init.go clientcmd\\lock.go clientcmd\\refresh.go clientcmd\\remote.go clientcmd\\switch.go clientconfig\\config.go clientconfig\\structures.go test\\test.go test.go]"}

View File

@@ -109,6 +109,9 @@ func main() {
// Adding the "pull" command
pullCommand(cli, &conf)
// Adding the "commit" command
commitCommand(cli, &conf)
err = cli.Run()
if err != nil {
fmt.Printf("Error occurred: %v\n", err)
@@ -685,3 +688,28 @@ func pullCommand(cli *clir.Cli, conf *config.Gvcconfig) {
return nil
})
}
func commitCommand(cli *clir.Cli, conf *config.Gvcconfig) {
commitCommand := cli.NewSubCommand("commit", "commits the changes to the repo")
var commitMessage string
commitMessageFlag := pullCommand.StringFlag("message", "adds a message to a commit", &commitMessage)
commitMessageFlag.FlagShortCut("message", "m")
commitCommand.Action(func() error {
isRepo := validateRepo()
if !isRepo {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
if len(commitCommand.OtherArgs()) == 0 {
commitCommand.PrintHelp()
fmt.Println("branch name required..")
os.Exit(0)
}
branchName := commitCommand.OtherArgs()[0]
err := clientcmd.SwitchBranch(conf, branchName)
if err != nil {
return fmt.Errorf("unable to pull branch: %s", err)
}
return nil
})
}

View File

@@ -1,7 +1,6 @@
package clientcmd
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -22,7 +21,6 @@ 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)
@@ -41,6 +39,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
// }
// }
relativePath := input //TODO: Figure out if path is corrrect?
relativePath = "test.go"
fmt.Println("Relative Path: ", relativePath)
err = m.AddFileToRepo(relativePath)
if err != nil {
@@ -57,22 +56,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return fmt.Errorf("file exists, but is not a folder %s", err)
}
filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path)
if err != nil {
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
if currentFile == ".gvc" { // can't track anything in .gvc
return SkipDir
if info.Name() == ".gvc" { // can't track anything in .gvc
fmt.Println("skipping .gvc directory")
m.Info().Msg("skipping .gvc directory")
return filepath.SkipDir
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(info.Name(), "folder", ignore)
if err != nil {
return SkipDir
fmt.Printf("skipping ignored directory: %s\n", err)
m.Info().Msgf("skipping ignored directory: %s\n", err)
return filepath.SkipDir
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(info.Name(), "file", ignore)
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
return nil
}
}
@@ -100,38 +102,44 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return err
}
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)
fmt.Printf("Checking file: %s\n", info.Name())
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
if info.Name() == ".gvc" { // can't track anything in .gvc
fmt.Println("skipping .gvc directory")
m.Info().Msg("skipping .gvc directory")
return filepath.SkipDir
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(info.Name(), "folder", ignore)
if err != nil {
return err
fmt.Printf("skipping ignored directory: %s\n", err)
m.Info().Msgf("skipping ignored directory: %s\n", err)
return filepath.SkipDir
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(info.Name(), "file", ignore)
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
return nil
}
}
fileExt := filepath.Ext(path)
if fileExt == wildcard { // seeing if the file ext matches the wildcard
fmt.Println("Adding file that matched wildcard: ", currentFile)
fmt.Println("Adding file that matched wildcard: ", info.Name())
relativePath, err := filepath.Rel(workingDir, path)
if err != nil {
return fmt.Errorf("unable to create relative path for file: %s", err)
fmt.Printf("unable to create relative path for file: %s\n", err)
m.Info().Msgf("unable to create relative path for file: %s\n", err)
return nil
}
fmt.Println("WILDCARD Relative Path: ", relativePath)
err = m.AddFileToRepo(relativePath)
if err != nil {
return fmt.Errorf("unable to add file to repo: %s", err)
fmt.Printf("unable to add file to repo: %s\n", err)
m.Info().Msgf("unable to add file to repo: %s\n", err)
return nil
}
trackedFiles = append(trackedFiles, relativePath)
}
@@ -139,22 +147,25 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
})
case "all":
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path)
if err != nil {
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
if currentFile == ".gvc" { // can't track anything in .gvc
return SkipDir
if info.Name() == ".gvc" { // can't track anything in .gvc
fmt.Println("skipping .gvc directory")
m.Info().Msg("skipping .gvc directory")
return filepath.SkipDir
}
err = common.CheckFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(info.Name(), "folder", ignore)
if err != nil {
return SkipDir
fmt.Printf("skipping ignored directory: %s\n", err)
m.Info().Msgf("skipping ignored directory: %s\n", err)
return filepath.SkipDir
}
} else {
err = common.CheckFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(info.Name(), "file", ignore)
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
fmt.Printf("Not adding file %s as it is on the ingores list \n", info.Name())
return nil
}
}
@@ -173,7 +184,13 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *manage
return nil
})
}
fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
if len(trackedFiles) > 0 {
fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
m.Info().Msgf("Adding the following files to tracked: %s", trackedFiles)
} else {
fmt.Println("No files found that could be added to tracked")
m.Info().Msg("No files found that could be added to tracked")
}
return nil
}

View File

@@ -0,0 +1,33 @@
package clientcmd
import (
"fmt"
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common/engine"
"github.com/deranjer/gvc/common/manager"
)
// Commit commits the tracked files and changes to the repo
func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *manager.Manager) error {
trackedFiles, err := m.FetchTrackedFiles()
if err != nil {
return err
}
for _, trackedFile := range trackedFiles {
currentFile, err := os.Stat(trackedFile.Path)
if err != nil {
fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err)
continue
}
currentFileHash, err := engine.UniqueFileHash(trackedFile.Path)
if err != nil {
fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
}
if currentFileHash == trackedFile.CurrentHash {
fmt.Printf("No changes found in file: %s when compared to file: %s\n", currentFile.Name(), trackedFile.Name)
}
}
return nil
}

0
client/test.go Normal file
View File

View File

@@ -39,17 +39,20 @@ 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)
return false
}
db.Warn().Msg("no file found")
fmt.Printf("Not found: %s error: %s\n", path, err)
return false
}
fmt.Printf("Found!: %s searched: %s\n", file.Path, path)
return true
}
// RetrieveWatchedFiles all files that are in the database as "watched files"
// RetrieveTrackedFiles all files that are in the database as "watched files"
// This can be used to trigger the same files to be watched again
func (db *DB) RetrieveWatchedFiles() ([]File, error) {
func (db *DB) RetrieveTrackedFiles() ([]File, error) {
var files []File
if err := db.All(&files); err != nil {
db.Err(err).Msg("Error retrieving all watched files")

View File

@@ -105,7 +105,6 @@ func (m *Manager) AddFileToRepo(relFilePath string) error {
// f := NewFileManager()
//DELAYED: this feature affects only large files and user experience. It can wait.
relFilePath = strings.TrimSpace(relFilePath) //purging any odd spaces TODO: Make sure not needed
fmt.Println("Checking for file: ", relFilePath)
var tmpFile database.File
filename := filepath.Base(relFilePath)
var hash [16]byte
@@ -160,3 +159,12 @@ func (m *Manager) prepareDatabaseForFile(tmpFile database.File) (int, error) {
return fileID, nil
}
// FetchTrackedFiles just grabbes all the files currently tracked in the repo
func (m *Manager) FetchTrackedFiles() ([]database.File, error) {
files, err := m.dB.RetrieveTrackedFiles()
if err != nil {
return nil, fmt.Errorf("unable to retrieve tracked files: %s", err)
}
return files, nil
}