From 5af55ed62e17b130cd3e281064877500b2611f91 Mon Sep 17 00:00:00 2001 From: deranjer Date: Thu, 2 Jul 2020 15:00:30 -0400 Subject: [PATCH] reworking database, init and add commands --- client/.gvc/.gvcconfig.toml | 46 +-------- client/.gvc/gvc.db | Bin 131072 -> 65536 bytes client/.gvc/logs/gvclog.log | 178 ++-------------------------------- client/client.go | 38 +++++--- client/clientcmd/add.go | 2 + client/clientcmd/commit.go | 7 +- client/clientcmd/commonlib.go | 2 +- client/clientcmd/init.go | 30 ++++-- common/database/create-db.go | 49 ++++++++-- common/database/db-ops.go | 27 +----- common/database/structures.go | 17 +++- common/engine/commits.go | 12 ++- common/engine/filesystem.go | 6 ++ common/engine/manager.go | 85 +++++++++++----- server/server.go | 16 ++- 15 files changed, 220 insertions(+), 295 deletions(-) diff --git a/client/.gvc/.gvcconfig.toml b/client/.gvc/.gvcconfig.toml index f937f1c..c37ad40 100644 --- a/client/.gvc/.gvcconfig.toml +++ b/client/.gvc/.gvcconfig.toml @@ -1,52 +1,12 @@ version = "0.1.5" -loglevel = 2 +loglevel = 0 rootpath = "" -reponame = "gvc" -currentbranch = "master" -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 +reponame = "" +currentbranch = "" [locked] - files = ["client1.exe", "client2.exe", "client.go", "serverLocked.go"] - exts = [".exeServer", "serverCOMP2EXT"] [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] - files = ["localnocompress.go"] - exts = ["serverNoCompressEXT", "serverCOMP2EXT"] - folders = [] diff --git a/client/.gvc/gvc.db b/client/.gvc/gvc.db index 6e6fec5974160b20bc6d490b8f9435fa457e7f79..6615d1e5a6c5d1d5ea0c27446dd20e47909eefe8 100644 GIT binary patch delta 431 zcmZo@;Am)InV`VPI{9O~_~e3l90E)X5TN_NOW%U$pv7j#h7J6a1QZyVCx6TrpWFac z!VFcCGU3AK{fYawLzF0R)x#th7z}_)Sb;bPh#7%+A`nXeu@#hm8AuBNu_X{2=o#vn zRx7!OIftbd6=&w>DOo9j#gufEJo7S3LNaqxfkH+GMh3bD=DG$(3Wg?DhL%>Q7J5b| z7G@@977DrsCI$uy4z4aC3c0r026_gDmIj7qKnye@D77HpFA;1+a!zJyUWrm|e0*_9 zeo=0GW?o8aMLfddiGdQ6BOFBdKrRQn08C6aaPXWwb$<571W&$623(W59QYL2q3#Fy zO&y52pnRZNo_T5cOq)$NoZ#Q&z$G9IQUM7AkblAIHal+E&p$CiWl{o%pa26Tz+u78 cyxH-?bN)#M9Goy2*3C60E!>*}K4iB50Fg;y1^@s6 literal 131072 zcmeI*TWlj&83%ATyW72AXeC5}Rw1oWfypv6zD}T2yUE_N-CK4y*=$+`$9BBV#&&8u z&1Nga142SV;t`OL`U0=;!V5y;i5DI#Atc08B_u=zMJpj5N~Khs}0f9WhVL?$lEz{#)h4;y?cM zqP3Q&Lo6rcbFC_n)UP=Epy*gXPIn5=Af{eLu()#E1C>;F%f_|NZFFMRX2 zBi~OXXGj4GP=Epypa2CZKmiI+fC3btz%CF7@AV@eBPqSIPo*9pej1MhCVwAb{b?&c zibjKHt#}Oas1;8n_FqB#8EgMiB3@6#-$DGGmHsWn_WS)j5&s6U{r>MDe!;vRPgDQG zk3(4h(-igr8aqB|_Lo*`l}6`ewYj*6EwXe)qFtqW`PE{%Y^T^0B~0y!Q!KTLjnW-E zkv6F8jT4oc^?I|hT3fQy?K2147pJRL8_ib5PV}Tn^r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Zun0u-RY?i2VAy@ObA diff --git a/client/.gvc/logs/gvclog.log b/client/.gvc/logs/gvclog.log index b3aba31..b3e01c4 100644 --- a/client/.gvc/logs/gvclog.log +++ b/client/.gvc/logs/gvclog.log @@ -1,173 +1,15 @@ {"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()\n"} {"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":"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":"Adding all files..."} {"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]"} +{"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"} diff --git a/client/client.go b/client/client.go index 5f5a746..db7bc62 100644 --- a/client/client.go +++ b/client/client.go @@ -11,6 +11,7 @@ import ( clientconfig "github.com/deranjer/gvc/client/clientconfig" config "github.com/deranjer/gvc/client/clientconfig" "github.com/deranjer/gvc/common" + "github.com/deranjer/gvc/common/database" "github.com/deranjer/gvc/common/engine" "github.com/deranjer/store" "github.com/rs/zerolog" @@ -18,6 +19,7 @@ import ( var version = "0.1.5" var configPath = ".gvc" + string(filepath.Separator) + ".gvcconfig.toml" +var dbPath = ".gvc/gvc.db" var rootPath string func main() { @@ -45,12 +47,6 @@ func main() { fmt.Println("Error validating config, your config file is corrupt! ", err) 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 logFile, err := os.OpenFile(".gvc/logs/gvclog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { @@ -62,15 +58,17 @@ func main() { if err != nil { fmt.Println("invalid log level set in config, setting to info") } + fmt.Println("Attempting to start logger...") clientlog := zerolog.New(logFile) clientlog.WithLevel(logLevel) - // Check/Setup the database with logging - //db, err := database.OpenOrCreateDB(".gvc/gvc.db", &clientlog) - //if err != nil { - // clientlog.Fatal().Msgf("Unable to open or create a database in the .gvc folder, fatal") - //} + // now checking the .gvc structure, currently will just create if they don't exist + dirPaths, err := engine.CheckPaths(rootPath) + if err != nil { + 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) - 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 { 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) // Adding the init command - initCommand(cli, &conf) + initCommand(cli, &conf, dbPath) // Adding all the "add" commands addCommands(cli, &conf, m) @@ -133,6 +131,11 @@ func validateRepo() bool { if _, err := os.Stat(configPath); os.IsNotExist(err) { 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 } @@ -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 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.Action(func() error { isRepo := validateRepo() 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{ RepoName: repoName, Version: version, CurrentBranch: "master", } - err := store.Save(configPath, &newConf) + err = store.Save(configPath, &newConf) if err != nil { log.Fatalf("unable to create new config in .gvc %s", err) } diff --git a/client/clientcmd/add.go b/client/clientcmd/add.go index 4ee312c..6492b1b 100644 --- a/client/clientcmd/add.go +++ b/client/clientcmd/add.go @@ -97,6 +97,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine } else { wildcard = input } + m.Info().Msgf("Adding all files with wildcard: %s", wildcard) err := common.CheckFileTypes(wildcard, "wildcard", ignore) if err != nil { return err @@ -146,6 +147,7 @@ func AddFiles(input string, inputType string, ignore common.FileTypes, m *engine return nil }) case "all": + m.Info().Msg("Adding all files...") filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error { if err != nil { return fmt.Errorf("failure accessing path %s", err) diff --git a/client/clientcmd/commit.go b/client/clientcmd/commit.go index f8e3c7e..99adca7 100644 --- a/client/clientcmd/commit.go +++ b/client/clientcmd/commit.go @@ -1,13 +1,18 @@ package clientcmd import ( + "fmt" + clientconfig "github.com/deranjer/gvc/client/clientconfig" "github.com/deranjer/gvc/common/engine" ) // Commit commits the tracked files and changes to the repo 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 } diff --git a/client/clientcmd/commonlib.go b/client/clientcmd/commonlib.go index 81678e9..bc637f3 100644 --- a/client/clientcmd/commonlib.go +++ b/client/clientcmd/commonlib.go @@ -25,7 +25,7 @@ func validateFileType(path string, inputType string) error { return fmt.Errorf("unable to read file, corrupted? %s", err) } if fileInfo.IsDir() { - if inputType == "folder" { + if inputType == "folder" || inputType == "all" { return nil } else { return fmt.Errorf("folder flag was used, but input is not a folder, will not continue") diff --git a/client/clientcmd/init.go b/client/clientcmd/init.go index 0c1f0e4..6ba07d0 100644 --- a/client/clientcmd/init.go +++ b/client/clientcmd/init.go @@ -2,23 +2,41 @@ package clientcmd import ( "fmt" - "log" "os" "path/filepath" + + "github.com/deranjer/gvc/common/database" + "github.com/deranjer/gvc/common/engine" ) // 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() 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) err = os.Mkdir(".gvc", 0644) 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) - return repoName + return repoName, nil } diff --git a/common/database/create-db.go b/common/database/create-db.go index 6810495..b750d09 100644 --- a/common/database/create-db.go +++ b/common/database/create-db.go @@ -1,23 +1,54 @@ package database import ( + "fmt" + "os" + "time" + "github.com/asdine/storm" "github.com/rs/zerolog" ) -type DB struct { - *storm.DB - *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) { +// OpenDB returns a new database object, from opening existing db +func OpenDB(dbPath string, log *zerolog.Logger, version string) (*DB, error) { var db DB + var err error databaseLogger := log.With().Str("module", "database").Logger() // Setting up a sub logger for the database module db.Logger = &databaseLogger - if err := db.ConfigureDB(dbPath); err != nil { - db.Err(err).Msg("unable to configure database") + db.DB, err = storm.Open(dbPath) + 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 } + defer db.Close() 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 +} diff --git a/common/database/db-ops.go b/common/database/db-ops.go index 71d5617..478220a 100644 --- a/common/database/db-ops.go +++ b/common/database/db-ops.go @@ -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 } diff --git a/common/database/structures.go b/common/database/structures.go index 507d3f9..ff92a2c 100644 --- a/common/database/structures.go +++ b/common/database/structures.go @@ -5,11 +5,26 @@ import ( "fmt" "io/ioutil" "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 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 Date string Version string //User can tag a commit with a version number diff --git a/common/engine/commits.go b/common/engine/commits.go index 86cf5c3..68f285a 100644 --- a/common/engine/commits.go +++ b/common/engine/commits.go @@ -1,6 +1,10 @@ package engine import ( + "encoding/hex" + "fmt" + "os" + "path/filepath" "time" "github.com/deranjer/gvc/common/database" @@ -21,9 +25,13 @@ func (m *Manager) CreateInitialCommit(fileList []database.File, commitMessage st initialCommit.Number = 1 initialCommit.TrackedFiles = fileList 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 { - go ConvertFileForStorage(&file, folder) + ConvertFileForStorage(&file, folder) } //var hashList [][]byte return nil diff --git a/common/engine/filesystem.go b/common/engine/filesystem.go index b451129..b285b49 100644 --- a/common/engine/filesystem.go +++ b/common/engine/filesystem.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "strings" "github.com/deranjer/gvc/common/database" @@ -95,6 +96,11 @@ func ConvertFileForStorage(file *database.File, folder string) error { return err } fmt.Println("REMOVE: ", fileBytes) + filename := folder + string(filepath.Separator) + file.Name + err = ioutil.WriteFile(filename, fileBytes, 0666) + if err != nil { + return err + } return nil } diff --git a/common/engine/manager.go b/common/engine/manager.go index 2d0d149..2355029 100644 --- a/common/engine/manager.go +++ b/common/engine/manager.go @@ -13,7 +13,6 @@ import ( "github.com/deranjer/gvc/common/database" "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 @@ -30,9 +29,10 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope ThumbFolder: dirPaths.ThumbFolder, DiffFolder: dirPaths.ObjectFolder, } - gvcDB, err := database.OpenOrCreateDB(dbPath, log) + gvcDB, err := database.OpenDB(dbPath, log, version) 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 m := Manager{ @@ -49,16 +49,16 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope return &m, nil } -// CheckPaths just checks the .gvc folder structure -func CheckPaths(rootDir string) (filePaths *FilePaths, err error) { +func generatePaths(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) rootFolder, err := filepath.Abs(rootDir) if err != nil { - return &FilePaths{}, err + return &fullFilePaths, err } path := rootFolder + string(filepath.Separator) + ".gvc" //path = filepath.Join(rootFolder, filepath.Separator+".gvc") - var fullFilePaths FilePaths + //where private and public keys are kept fullFilePaths.KeyFolder = filepath.Join(path, "keys") //where downloaded files start @@ -73,7 +73,45 @@ func CheckPaths(rootDir string) (filePaths *FilePaths, err error) { fullFilePaths.LogFolder = filepath.Join(path, "logs") //where plugins are stored 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.DownloadFolder) InitiateDirectory(fullFilePaths.SyncFolder) @@ -81,7 +119,7 @@ func CheckPaths(rootDir string) (filePaths *FilePaths, err error) { InitiateDirectory(fullFilePaths.ThumbFolder) InitiateDirectory(fullFilePaths.LogFolder) InitiateDirectory(fullFilePaths.PluginFolder) - return &fullFilePaths, nil + return nil } // 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 { - trackedFiles, err := m.FetchTrackedFiles() + fmt.Println("Beginning Commit on Branch: ", branch) + trackedFiles, err := m.dB.RetrieveTrackedFiles() if err != nil { 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 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) if err != nil { fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err) continue } + currentFileHash, err := UniqueFileHash(trackedFile.Path) if err != nil { 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) } - diffChannel := make(chan database.DiffObject) - diffContext := context.Background() - m.WaitGroup.Add(2) + //diffChannel := make(chan database.DiffObject) + //diffContext := context.Background() + //m.WaitGroup.Add(2) commit, err := m.dB.FetchLastCommitOnBranch(branch) if err != nil { 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 { m.Err(err).Msgf("unable to create initial commit: %s", err) return err } } + fmt.Println("COMMIT: ", commit.CommitHash) return nil } @@ -207,12 +257,3 @@ func (m *Manager) FetchCommitByNumber(branch string, commitNumber string) error 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 -} diff --git a/server/server.go b/server/server.go index a175b7b..d7c2a8f 100644 --- a/server/server.go +++ b/server/server.go @@ -66,7 +66,21 @@ func main() { serverlog := zerolog.New(logFile) serverlog.WithLevel(logLevel) // 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 e := echo.New() // Setup the logger to print to the file specified in config