moving to one source
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Arnas Udovic 2023-06-29 00:10:54 +03:00
parent 9b60784dbb
commit 760753c7b8
6 changed files with 14 additions and 51 deletions

View file

@ -6,13 +6,9 @@ import (
) )
func Collect() { func Collect() {
if _, err := os.Stat(dest); os.IsNotExist(err) {
panic("Destination directory does not exist.")
}
if _, err := os.Stat(source); os.IsNotExist(err) { if _, err := os.Stat(source); os.IsNotExist(err) {
panic("Source directory does not exist.") panic("Source directory does not exist.")
} }
_ = zord_tree.PopulateTree(source, dest, meta, customMeta) _ = zord_tree.PopulateTree(source, meta, customMeta)
} }

View file

@ -6,7 +6,7 @@ import (
) )
func FormatTreeSummery(tree zordTree.Tree) Tree { func FormatTreeSummery(tree zordTree.Tree) Tree {
path := strings.Replace(tree.Path, dest, "", 1) path := strings.Replace(tree.Path, source, "", 1)
pathParts := strings.Split(path, "/") pathParts := strings.Split(path, "/")
rootPath := strings.Join(pathParts[:len(pathParts)-1], "/") rootPath := strings.Join(pathParts[:len(pathParts)-1], "/")
ts := Tree{RootPath: rootPath, Path: path} ts := Tree{RootPath: rootPath, Path: path}

3
go.mod
View file

@ -3,7 +3,7 @@ module g.arns.lt/zordsdavini/arns-lt-tree-push-service
go 1.19 go 1.19
require ( require (
g.arns.lt/zordsdavini/zord-tree v0.2.7 g.arns.lt/zordsdavini/zord-tree v0.3.1
google.golang.org/grpc v1.48.0 google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1 google.golang.org/protobuf v1.28.1
) )
@ -11,7 +11,6 @@ require (
require ( require (
g.arns.lt/zordsdavini/abcex v1.0.0 // indirect g.arns.lt/zordsdavini/abcex v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/otiai10/copy v1.6.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.1.0 // indirect golang.org/x/sys v0.1.0 // indirect

10
go.sum
View file

@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
g.arns.lt/zordsdavini/abcex v1.0.0 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E= g.arns.lt/zordsdavini/abcex v1.0.0 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E=
g.arns.lt/zordsdavini/abcex v1.0.0/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8= g.arns.lt/zordsdavini/abcex v1.0.0/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8=
g.arns.lt/zordsdavini/zord-tree v0.2.7 h1:h19O+VmzaXA9E68XWIDTF4VIU4I1TnTd8TPigRCljLQ= g.arns.lt/zordsdavini/zord-tree v0.3.1 h1:oBXWJ85zCUEhcNDf5YNLaWg5QfsPw3Fw0ngWWsuuisA=
g.arns.lt/zordsdavini/zord-tree v0.2.7/go.mod h1:HG++MTNUD8oQHrkTdVnClm0q82lGumASn4GWJtWQApY= g.arns.lt/zordsdavini/zord-tree v0.3.1/go.mod h1:HG++MTNUD8oQHrkTdVnClm0q82lGumASn4GWJtWQApY=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -50,12 +50,6 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ= github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ=
github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=

View file

@ -7,14 +7,12 @@ import (
var ( var (
source string source string
dest string
key string key string
meta = []string{"description", "lang", "copyright", "created"} //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta) meta = []string{"description", "lang", "copyright", "created"} //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta)
customMeta = make(map[string]func() string) customMeta = make(map[string]func() string)
) )
func init() { func init() {
flag.StringVar(&dest, "dest", "", "destination directory to read from")
flag.StringVar(&source, "source", "", "source to collect texts.") flag.StringVar(&source, "source", "", "source to collect texts.")
flag.StringVar(&key, "key", "", "secret key for authenticated communication.") flag.StringVar(&key, "key", "", "secret key for authenticated communication.")
flag.Parse() flag.Parse()

View file

@ -3,15 +3,13 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
zordTree "g.arns.lt/zordsdavini/zord-tree"
"google.golang.org/grpc" "google.golang.org/grpc"
"io" "io"
"log" "log"
"net" "net"
"os" "os"
"path" "path"
"path/filepath"
zordTree "g.arns.lt/zordsdavini/zord-tree"
) )
type server struct { type server struct {
@ -20,14 +18,14 @@ type server struct {
func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) (*Tree, error) { func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) (*Tree, error) {
log.Println(in) log.Println(in)
tree, err := zordTree.BuildTree(dest, meta) tree, err := zordTree.BuildTree(source, meta)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return nil, err return nil, err
} }
if *in.Path != "" { if *in.Path != "" {
ntree, err := tree.Slice(dest + *in.Path) ntree, err := tree.Slice(source + *in.Path)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return &Tree{}, err return &Tree{}, err
@ -52,7 +50,7 @@ func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest)
func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*FileContent, error) { func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*FileContent, error) {
log.Println(in) log.Println(in)
tree, err := zordTree.BuildTree(dest, meta) tree, err := zordTree.BuildTree(source, meta)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return nil, err return nil, err
@ -71,19 +69,16 @@ func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*F
func (TreeManagerServer *server) RebuildTree(ctx context.Context, in *TreeSecret) (*RebuildResponse, error) { func (TreeManagerServer *server) RebuildTree(ctx context.Context, in *TreeSecret) (*RebuildResponse, error) {
success := false success := false
if in.Key == key { if in.Key == key {
err := removeContents(dest)
if err == nil {
Collect() Collect()
success = true success = true
} }
}
response := RebuildResponse{Success: success} response := RebuildResponse{Success: success}
return &response, nil return &response, nil
} }
func (TreeManagerServer *server) DownloadAttachment(in *AttachmentRequest, responseStream TreeManager_DownloadAttachmentServer) error { func (TreeManagerServer *server) DownloadAttachment(in *AttachmentRequest, responseStream TreeManager_DownloadAttachmentServer) error {
file, err := os.Open(path.Clean(fmt.Sprintf("%s/%s/%s", dest, "__a", in.Path))) file, err := os.Open(path.Clean(fmt.Sprintf("%s/%s/%s", source, zordTree.AttachmentDirName, in.Path)))
if err != nil { if err != nil {
return err return err
} }
@ -109,25 +104,6 @@ func (TreeManagerServer *server) DownloadAttachment(in *AttachmentRequest, respo
return nil return nil
} }
func removeContents(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll(filepath.Join(dir, name))
if err != nil {
return err
}
}
return nil
}
func simplifyFilter(filter []*TreeRequest_Filter) map[string][]string { func simplifyFilter(filter []*TreeRequest_Filter) map[string][]string {
simpleFilter := make(map[string][]string) simpleFilter := make(map[string][]string)
for _, f := range filter { for _, f := range filter {
@ -138,8 +114,8 @@ func simplifyFilter(filter []*TreeRequest_Filter) map[string][]string {
} }
func Run() { func Run() {
if _, err := os.Stat(dest); os.IsNotExist(err) { if _, err := os.Stat(source); os.IsNotExist(err) {
log.Fatalf("Destination directory does not exist.") log.Fatalf("Source directory does not exist.")
} }
ln, err := net.Listen("tcp", ":8301") ln, err := net.Listen("tcp", ":8301")