reworking database, init and add commands

This commit is contained in:
2020-07-02 15:00:30 -04:00
parent 6379c73e38
commit 5af55ed62e
15 changed files with 220 additions and 295 deletions

View File

@@ -1,52 +1,12 @@
version = "0.1.5" version = "0.1.5"
loglevel = 2 loglevel = 0
rootpath = "" rootpath = ""
reponame = "gvc" reponame = ""
currentbranch = "master" currentbranch = ""
localbranches = ["master", "localbranch1", "localbranch2"]
remotebranches = ["master", "serveronlybranch", "anotherserverbranch"]
[[remote]]
name = "test2"
host = "localhost"
port = 80
default = true
[[remote]]
name = "test4"
host = "localhost"
port = 9998
default = false
[[remote]]
name = "test3"
host = "localhost"
port = 9997
default = false
[[remote]]
name = "test5"
host = "localhost1"
port = 9997
default = false
[[remote]]
name = "test6"
host = "localhost1"
port = 9995
default = false
[locked] [locked]
files = ["client1.exe", "client2.exe", "client.go", "serverLocked.go"]
exts = [".exeServer", "serverCOMP2EXT"]
[ignore] [ignore]
files = ["client1.exe", "client2.exe", "client3.exe", "client4.exe", "client5.exe", "client6.exe", "client7.exe", "test1\\client8.exe", "clientcmd\\init.go", "localignoreonly.go"]
exts = [".exe", ".tl"]
folders = ["serverFolderIgnore", "serverFolderignore2"]
[nocompress] [nocompress]
files = ["localnocompress.go"]
exts = ["serverNoCompressEXT", "serverCOMP2EXT"]
folders = []

Binary file not shown.

View File

@@ -1,173 +1,15 @@
{"level":"info","message":"Creating new Manager..."} {"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..."}
{"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":"Creating new Manager..."}
{"level":"info","message":"Adding all files..."}
{"level":"info","message":"skipping .gvc directory"} {"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"} {"level":"error","module":"database","error":"database not open","message":"Error finding file by path"}
{"level":"error","module":"database","error":"database not open","message":"Error initialising file in database"}
{"level":"error","message":"Error checking if file [.gvcignore.toml] is monitored. Error database not open"}
{"level":"info","message":"No files found that could be added to tracked"}
{"level":"info","message":"Creating new Manager..."} {"level":"info","message":"Creating new Manager..."}
{"level":"info","message":"Adding all files..."}
{"level":"info","message":"skipping .gvc directory"} {"level":"info","message":"skipping .gvc directory"}
{"level":"info","message":"skipping .gvc directory"} {"level":"error","module":"database","error":"database not open","message":"Error finding file by path"}
{"level":"info","message":"Creating new Manager..."} {"level":"error","module":"database","error":"database not open","message":"Error initialising file in database"}
{"level":"info","message":"skipping .gvc directory"} {"level":"error","message":"Error checking if file [.gvcignore.toml] is monitored. Error database not open"}
{"level":"info","message":"unable to add file to repo: file already found in tracked files, not adding: client.go\n"} {"level":"info","message":"No files found that could be added to tracked"}
{"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

@@ -11,6 +11,7 @@ import (
clientconfig "github.com/deranjer/gvc/client/clientconfig" clientconfig "github.com/deranjer/gvc/client/clientconfig"
config "github.com/deranjer/gvc/client/clientconfig" config "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common" "github.com/deranjer/gvc/common"
"github.com/deranjer/gvc/common/database"
"github.com/deranjer/gvc/common/engine" "github.com/deranjer/gvc/common/engine"
"github.com/deranjer/store" "github.com/deranjer/store"
"github.com/rs/zerolog" "github.com/rs/zerolog"
@@ -18,6 +19,7 @@ import (
var version = "0.1.5" var version = "0.1.5"
var configPath = ".gvc" + string(filepath.Separator) + ".gvcconfig.toml" var configPath = ".gvc" + string(filepath.Separator) + ".gvcconfig.toml"
var dbPath = ".gvc/gvc.db"
var rootPath string var rootPath string
func main() { func main() {
@@ -45,12 +47,6 @@ func main() {
fmt.Println("Error validating config, your config file is corrupt! ", err) fmt.Println("Error validating config, your config file is corrupt! ", err)
os.Exit(0) os.Exit(0)
} }
fmt.Println("Attempting to start logger...")
// Checking the .gvc structure
dirPaths, err := engine.CheckPaths(rootPath)
if err != nil {
log.Fatalf("unable to create/verify .gvc folder structure: %s", err)
}
// Setting up the logger to file output // 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) logFile, err := os.OpenFile(".gvc/logs/gvclog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil { if err != nil {
@@ -62,15 +58,17 @@ func main() {
if err != nil { if err != nil {
fmt.Println("invalid log level set in config, setting to info") fmt.Println("invalid log level set in config, setting to info")
} }
fmt.Println("Attempting to start logger...")
clientlog := zerolog.New(logFile) clientlog := zerolog.New(logFile)
clientlog.WithLevel(logLevel) clientlog.WithLevel(logLevel)
// Check/Setup the database with logging // now checking the .gvc structure, currently will just create if they don't exist
//db, err := database.OpenOrCreateDB(".gvc/gvc.db", &clientlog) dirPaths, err := engine.CheckPaths(rootPath)
//if err != nil { if err != nil {
// clientlog.Fatal().Msgf("Unable to open or create a database in the .gvc folder, fatal") clientlog.Err(err).Msgf("unable to verify .gvc folder structure, attempting to create missing structure: %s", err)
//} }
engine.CreatePaths(rootPath) //currently will fatal fail if can't create paths
informer := make(chan engine.OperatingMessage) informer := make(chan engine.OperatingMessage)
m, err = engine.NewManager(rootPath, version, ".gvc/gvc.db", informer, dirPaths, &clientlog) m, err = engine.NewManager(rootPath, version, dbPath, informer, dirPaths, &clientlog)
if err != nil { if err != nil {
clientlog.Fatal().Msgf("unable to create new manager object... %s", err) clientlog.Fatal().Msgf("unable to create new manager object... %s", err)
} }
@@ -80,7 +78,7 @@ func main() {
cli := clir.NewCli("gvcc", "Version control client for GVC", version) cli := clir.NewCli("gvcc", "Version control client for GVC", version)
// Adding the init command // Adding the init command
initCommand(cli, &conf) initCommand(cli, &conf, dbPath)
// Adding all the "add" commands // Adding all the "add" commands
addCommands(cli, &conf, m) addCommands(cli, &conf, m)
@@ -133,6 +131,11 @@ func validateRepo() bool {
if _, err := os.Stat(configPath); os.IsNotExist(err) { if _, err := os.Stat(configPath); os.IsNotExist(err) {
return false return false
} }
// See if database exits, if not, not a valid repo
err := database.CheckDB(".gvc/gvc.db")
if err != nil {
return false
}
return true return true
} }
@@ -154,20 +157,23 @@ func refreshCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
}) })
} }
func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) { func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig, dbPath string) {
//The init subcommand //The init subcommand
initCmd := cli.NewSubCommand("init", "initializes a new gvc repo") initCmd := cli.NewSubCommand("init", "initializes a new gvc repo")
initCmd.LongDescription("This will create the .gvcconfig.toml (with defaults) file in this directory. You can edit this file directly (unsafe) or with the client(safe)") initCmd.LongDescription("This will create the .gvcconfig.toml (with defaults) file in this directory. You can edit this file directly (unsafe) or with the client(safe)")
initCmd.Action(func() error { initCmd.Action(func() error {
isRepo := validateRepo() isRepo := validateRepo()
if !isRepo { if !isRepo {
repoName := clientcmd.InitializeRepo() // creates and checks the paths repoName, err := clientcmd.InitializeRepo(dbPath, version, rootPath) // creates and checks the paths
if err != nil {
log.Fatalf("unable to create new repo: %s", err)
}
newConf := clientconfig.Gvcconfig{ newConf := clientconfig.Gvcconfig{
RepoName: repoName, RepoName: repoName,
Version: version, Version: version,
CurrentBranch: "master", CurrentBranch: "master",
} }
err := store.Save(configPath, &newConf) err = store.Save(configPath, &newConf)
if err != nil { if err != nil {
log.Fatalf("unable to create new config in .gvc %s", err) log.Fatalf("unable to create new config in .gvc %s", err)
} }

View File

@@ -97,6 +97,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine
} else { } else {
wildcard = input wildcard = input
} }
m.Info().Msgf("Adding all files with wildcard: %s", wildcard)
err := common.CheckFileTypes(wildcard, "wildcard", ignore) err := common.CheckFileTypes(wildcard, "wildcard", ignore)
if err != nil { if err != nil {
return err return err
@@ -146,6 +147,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine
return nil return nil
}) })
case "all": case "all":
m.Info().Msg("Adding all files...")
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error { filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return fmt.Errorf("failure accessing path %s", err) return fmt.Errorf("failure accessing path %s", err)

View File

@@ -1,13 +1,18 @@
package clientcmd package clientcmd
import ( import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig" clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common/engine" "github.com/deranjer/gvc/common/engine"
) )
// Commit commits the tracked files and changes to the repo // Commit commits the tracked files and changes to the repo
func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *engine.Manager) error { func Commit(conf *clientconfig.Gvcconfig, commitMessage string, m *engine.Manager) error {
m.BeginCommit(conf.CurrentBranch, commitMessage) err := m.BeginCommit(conf.CurrentBranch, commitMessage)
if err != nil {
return fmt.Errorf("begin commit failed with message: %s", err)
}
return nil return nil
} }

View File

@@ -25,7 +25,7 @@ func validateFileType(path string, inputType string) error {
return fmt.Errorf("unable to read file, corrupted? %s", err) return fmt.Errorf("unable to read file, corrupted? %s", err)
} }
if fileInfo.IsDir() { if fileInfo.IsDir() {
if inputType == "folder" { if inputType == "folder" || inputType == "all" {
return nil return nil
} else { } else {
return fmt.Errorf("folder flag was used, but input is not a folder, will not continue") return fmt.Errorf("folder flag was used, but input is not a folder, will not continue")

View File

@@ -2,23 +2,41 @@ package clientcmd
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"github.com/deranjer/gvc/common/database"
"github.com/deranjer/gvc/common/engine"
) )
// InitializeRepo creates the repo directory and a new config file // InitializeRepo creates the repo directory and a new config file
func InitializeRepo() string { func InitializeRepo(dbPath string, version string, rootPath string) (string, error) {
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {
log.Fatal("unable to get current working directory.. permissions issue?") fmt.Printf("unable to get current working directory.. permissions issue? %s\n", err)
return "", err
} }
repoName := filepath.Base(cwd)
fmt.Println("Initializing repo in dir: ", cwd) fmt.Println("Initializing repo in dir: ", cwd)
err = os.Mkdir(".gvc", 0644) err = os.Mkdir(".gvc", 0644)
if err != nil { if err != nil {
fmt.Println(".gvc directory already exists, but no config file... continuing") fmt.Printf(".gvc directory already exists, but no config file... continuing")
}
err = engine.CreatePaths(rootPath)
if err != nil {
fmt.Printf("unable to create root dir paths.. permissions issue? %s\n", err)
return "", err
}
fmt.Println("Creating DB...")
err = database.CreateDB(dbPath, version, repoName)
if err != nil {
fmt.Printf("unable to create db: %s\n", err)
err := os.Remove(dbPath)
if err != nil {
fmt.Printf("unable to roll back database, cannot delete db: %s err: %s", dbPath, err)
}
return "", err
} }
repoName := filepath.Base(cwd)
fmt.Println("Adding new repo with name: ", repoName) fmt.Println("Adding new repo with name: ", repoName)
return repoName return repoName, nil
} }

View File

@@ -1,23 +1,54 @@
package database package database
import ( import (
"fmt"
"os"
"time"
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
type DB struct { // OpenDB returns a new database object, from opening existing db
*storm.DB func OpenDB(dbPath string, log *zerolog.Logger, version string) (*DB, error) {
*zerolog.Logger
}
// OpenOrCreate returns a new database object, either from existing database or creates a new one
func OpenOrCreateDB(dbPath string, log *zerolog.Logger) (*DB, error) {
var db DB var db DB
var err error
databaseLogger := log.With().Str("module", "database").Logger() // Setting up a sub logger for the database module databaseLogger := log.With().Str("module", "database").Logger() // Setting up a sub logger for the database module
db.Logger = &databaseLogger db.Logger = &databaseLogger
if err := db.ConfigureDB(dbPath); err != nil { db.DB, err = storm.Open(dbPath)
db.Err(err).Msg("unable to configure database") if err != nil {
db.Err(err).Msg("No existing database found. this does not appear to be a repo, please init repo")
return &db, err return &db, err
} }
defer db.Close()
return &db, nil return &db, nil
} }
// CreateDB sets up bolt and Storm according to the path of the database //TODO: Save a backup of the config in DB on creation
func CreateDB(dbPath string, version string, repoName string) error {
db, err := storm.Open(dbPath)
if err != nil {
fmt.Println("error initializing database")
return err
}
defer db.Close()
fmt.Println("Initializing new database..")
initTime := time.Now().String()
var gvcInit GVCInfo
gvcInit.InitTime = initTime
gvcInit.GVCVersion = version
gvcInit.RepoName = repoName
if err := db.Save(&gvcInit); err != nil {
fmt.Println("Unable to init db")
return err
}
return nil
}
// CheckDB checks to see if database exists
func CheckDB(dbPath string) error {
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
return err
}
return nil
}

View File

@@ -3,34 +3,9 @@ package database
import ( import (
"fmt" "fmt"
"github.com/asdine/storm"
"github.com/asdine/storm/q" "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 // CheckIfFileCurrentlyMonitored checks if the file is already being monitored. This is a read-only check
// to see whether the file was correctly initialised // to see whether the file was correctly initialised
// (BUG) The hash causes the same file to be in database multiple times! // (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 // This can be used to trigger the same files to be watched again
func (db *DB) RetrieveTrackedFiles() ([]File, error) { func (db *DB) RetrieveTrackedFiles() ([]File, error) {
var files []File var files []File
fmt.Println("Starting file extraction")
if err := db.All(&files); err != nil { if err := db.All(&files); err != nil {
db.Err(err).Msg("Error retrieving all watched files") db.Err(err).Msg("Error retrieving all watched files")
return []File{}, err return []File{}, err
} }
fmt.Println("Ending file extraction")
return files, nil return files, nil
} }

View File

@@ -5,11 +5,26 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"time" "time"
"github.com/asdine/storm"
"github.com/rs/zerolog"
) )
type DB struct {
*storm.DB
*zerolog.Logger
}
// GVCInfo stores the basic information about when the repo was init'd and some basic information
type GVCInfo struct {
GVCVersion string `storm:"id"`
InitTime string
RepoName string
}
// Commit stores all the necessary information for a commit // Commit stores all the necessary information for a commit
type Commit struct { type Commit struct {
CommitHash []byte // The hash of the commit (generated by hashing commit author name, time, the previous commit, and more? TODO: Not sure what else) CommitHash []byte `storm:"index,unique"` // The hash of the commit (generated by hashing commit author name, time, the previous commit, and more? TODO: Not sure what else)
TrackedFiles []File // All of the tracked files for this commit TrackedFiles []File // All of the tracked files for this commit
Date string Date string
Version string //User can tag a commit with a version number Version string //User can tag a commit with a version number

View File

@@ -1,6 +1,10 @@
package engine package engine
import ( import (
"encoding/hex"
"fmt"
"os"
"path/filepath"
"time" "time"
"github.com/deranjer/gvc/common/database" "github.com/deranjer/gvc/common/database"
@@ -21,9 +25,13 @@ func (m *Manager) CreateInitialCommit(fileList []database.File, commitMessage st
initialCommit.Number = 1 initialCommit.Number = 1
initialCommit.TrackedFiles = fileList initialCommit.TrackedFiles = fileList
initialCommit.Date = currentTime.String() initialCommit.Date = currentTime.String()
folder := m.FilePaths.ObjectFolder + string(filepath.Separator) + hex.EncodeToString(hashBytes)
err = os.Mkdir(folder, 0666)
if err != nil {
return fmt.Errorf("unable to create commit directory in object dir: %s err: %s", folder, err)
}
for _, file := range fileList { for _, file := range fileList {
go ConvertFileForStorage(&file, folder) ConvertFileForStorage(&file, folder)
} }
//var hashList [][]byte //var hashList [][]byte
return nil return nil

View File

@@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/deranjer/gvc/common/database" "github.com/deranjer/gvc/common/database"
@@ -95,6 +96,11 @@ func ConvertFileForStorage(file *database.File, folder string) error {
return err return err
} }
fmt.Println("REMOVE: ", fileBytes) fmt.Println("REMOVE: ", fileBytes)
filename := folder + string(filepath.Separator) + file.Name
err = ioutil.WriteFile(filename, fileBytes, 0666)
if err != nil {
return err
}
return nil return nil
} }

View File

@@ -13,7 +13,6 @@ import (
"github.com/deranjer/gvc/common/database" "github.com/deranjer/gvc/common/database"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"golang.org/x/net/context"
) )
// NewManager creates a new manager interface that contains all the needed information to make changes to the repo // NewManager creates a new manager interface that contains all the needed information to make changes to the repo
@@ -30,9 +29,10 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope
ThumbFolder: dirPaths.ThumbFolder, ThumbFolder: dirPaths.ThumbFolder,
DiffFolder: dirPaths.ObjectFolder, DiffFolder: dirPaths.ObjectFolder,
} }
gvcDB, err := database.OpenOrCreateDB(dbPath, log) gvcDB, err := database.OpenDB(dbPath, log, version)
if err != nil { if err != nil {
log.Fatal().Msgf("unable to create or open db: %s", err) log.Err(err).Msgf("unable to create or open db: %s", err)
return nil, err
} }
var wg *sync.WaitGroup var wg *sync.WaitGroup
m := Manager{ m := Manager{
@@ -49,16 +49,16 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope
return &m, nil return &m, nil
} }
// CheckPaths just checks the .gvc folder structure func generatePaths(rootDir string) (filePaths *FilePaths, err error) {
func CheckPaths(rootDir string) (filePaths *FilePaths, err error) { var fullFilePaths FilePaths
// checking for the .gvc folder (the client (but not the server) already checks for the .gvc folder, but this checks all subdirects to make sure they are there) // checking for the .gvc folder (the client (but not the server) already checks for the .gvc folder, but this checks all subdirects to make sure they are there)
rootFolder, err := filepath.Abs(rootDir) rootFolder, err := filepath.Abs(rootDir)
if err != nil { if err != nil {
return &FilePaths{}, err return &fullFilePaths, err
} }
path := rootFolder + string(filepath.Separator) + ".gvc" path := rootFolder + string(filepath.Separator) + ".gvc"
//path = filepath.Join(rootFolder, filepath.Separator+".gvc") //path = filepath.Join(rootFolder, filepath.Separator+".gvc")
var fullFilePaths FilePaths
//where private and public keys are kept //where private and public keys are kept
fullFilePaths.KeyFolder = filepath.Join(path, "keys") fullFilePaths.KeyFolder = filepath.Join(path, "keys")
//where downloaded files start //where downloaded files start
@@ -73,7 +73,45 @@ func CheckPaths(rootDir string) (filePaths *FilePaths, err error) {
fullFilePaths.LogFolder = filepath.Join(path, "logs") fullFilePaths.LogFolder = filepath.Join(path, "logs")
//where plugins are stored //where plugins are stored
fullFilePaths.PluginFolder = filepath.Join(path, "plugins") fullFilePaths.PluginFolder = filepath.Join(path, "plugins")
return &fullFilePaths, nil
}
// CheckPaths just checks the .gvc folder structure
func CheckPaths(rootDir string) (filePaths *FilePaths, err error) {
fullFilePaths, err := generatePaths(rootDir)
if err != nil {
return nil, fmt.Errorf("unable to generate paths, err: %s", err)
}
if _, err := os.Stat(fullFilePaths.DownloadFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.KeyFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.LogFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.ObjectFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.PluginFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.SyncFolder); os.IsNotExist(err) {
return nil, err
}
if _, err := os.Stat(fullFilePaths.ThumbFolder); os.IsNotExist(err) {
return nil, err
}
return fullFilePaths, nil
}
// CreatePaths creates the paths needed in the .gvc folder
func CreatePaths(rootDir string) error {
fullFilePaths, err := generatePaths(rootDir)
if err != nil {
return fmt.Errorf("unable to generate file paths.. %s", err)
}
InitiateDirectory(fullFilePaths.KeyFolder) InitiateDirectory(fullFilePaths.KeyFolder)
InitiateDirectory(fullFilePaths.DownloadFolder) InitiateDirectory(fullFilePaths.DownloadFolder)
InitiateDirectory(fullFilePaths.SyncFolder) InitiateDirectory(fullFilePaths.SyncFolder)
@@ -81,7 +119,7 @@ func CheckPaths(rootDir string) (filePaths *FilePaths, err error) {
InitiateDirectory(fullFilePaths.ThumbFolder) InitiateDirectory(fullFilePaths.ThumbFolder)
InitiateDirectory(fullFilePaths.LogFolder) InitiateDirectory(fullFilePaths.LogFolder)
InitiateDirectory(fullFilePaths.PluginFolder) InitiateDirectory(fullFilePaths.PluginFolder)
return &fullFilePaths, nil return nil
} }
// This adds a file for the watcher to keep an eye on // This adds a file for the watcher to keep an eye on
@@ -164,18 +202,29 @@ func (m *Manager) prepareDatabaseForFile(tmpFile database.File) (int, error) {
} }
// BeginCommit starts the commit process
func (m *Manager) BeginCommit(branch string, commitMessage string) error { func (m *Manager) BeginCommit(branch string, commitMessage string) error {
trackedFiles, err := m.FetchTrackedFiles() fmt.Println("Beginning Commit on Branch: ", branch)
trackedFiles, err := m.dB.RetrieveTrackedFiles()
if err != nil { if err != nil {
return err return err
} }
if len(trackedFiles) == 0 {
return fmt.Errorf("no files show as tracked in repo, cannot commit, aborting...")
}
var filesToDiff []database.File // Contains the list of files that have changed var filesToDiff []database.File // Contains the list of files that have changed
for _, trackedFile := range trackedFiles { for _, trackedFile := range trackedFiles {
fmt.Println("Working on file: ", trackedFile.Path)
if trackedFile.Path == "" {
fmt.Println("No filepath found for file: ", trackedFile.Name)
continue
}
currentFile, err := os.Stat(trackedFile.Path) currentFile, err := os.Stat(trackedFile.Path)
if err != nil { if err != nil {
fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err) fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err)
continue continue
} }
currentFileHash, err := UniqueFileHash(trackedFile.Path) currentFileHash, err := UniqueFileHash(trackedFile.Path)
if err != nil { if err != nil {
fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err) fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
@@ -188,18 +237,19 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
} }
filesToDiff = append(filesToDiff, trackedFile) filesToDiff = append(filesToDiff, trackedFile)
} }
diffChannel := make(chan database.DiffObject) //diffChannel := make(chan database.DiffObject)
diffContext := context.Background() //diffContext := context.Background()
m.WaitGroup.Add(2) //m.WaitGroup.Add(2)
commit, err := m.dB.FetchLastCommitOnBranch(branch) commit, err := m.dB.FetchLastCommitOnBranch(branch)
if err != nil { if err != nil {
m.Info().Msgf("unable to fetch last commit on branch, assuming first commit on branch", err) m.Info().Msgf("unable to fetch last commit on branch, assuming first commit on branch", err)
err := CreateInitialCommit(filesToDiff, commitMessage) err := m.CreateInitialCommit(filesToDiff, commitMessage)
if err != nil { if err != nil {
m.Err(err).Msgf("unable to create initial commit: %s", err) m.Err(err).Msgf("unable to create initial commit: %s", err)
return err return err
} }
} }
fmt.Println("COMMIT: ", commit.CommitHash)
return nil return nil
} }
@@ -207,12 +257,3 @@ func (m *Manager) FetchCommitByNumber(branch string, commitNumber string) error
return nil return 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
}

View File

@@ -66,7 +66,21 @@ func main() {
serverlog := zerolog.New(logFile) serverlog := zerolog.New(logFile)
serverlog.WithLevel(logLevel) serverlog.WithLevel(logLevel)
// Check/Setup the database // Check/Setup the database
database.OpenOrCreateDB(conf.DatabaseLocation, &serverlog) var serverDB *database.DB
err = database.CheckDB(conf.DatabaseLocation)
if err != nil {
serverlog.Info().Msg("No database found, creating...")
err := database.CreateDB(conf.DatabaseLocation, version, "none")
if err != nil {
serverlog.Fatal().Msgf("unable to create database: %s", err)
}
serverDB, err = database.OpenDB(conf.DatabaseLocation, &serverlog, version)
if err != nil {
serverlog.Fatal().Msgf("unable to open database: %s", err)
}
defer serverDB.Close()
}
serverDB.Info().Msg("database initialized")
// Setup the web server // Setup the web server
e := echo.New() e := echo.New()
// Setup the logger to print to the file specified in config // Setup the logger to print to the file specified in config