Skip to content

Commit

Permalink
fix for recursive search
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
  • Loading branch information
jdolitsky committed Jan 13, 2019
1 parent 110c52e commit 54a5d09
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ clean:
.PHONY: get-version
get-version:
@echo $(VERSION)

.PHONY: fix-deps
fix-deps:
cp storage_fix.go vendor/github.com/chartmuseum/storage/storage.go
8 changes: 8 additions & 0 deletions cmd/chart-scanner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func cliHandler(c *cli.Context) {
if err != nil {
log.Fatal(err)
}

backend := backendFromConfig(conf)

// First make sure we have access to the root storage dir
err = check(backend)
if err != nil {
log.Fatal(err)
}

scan(backend, "")
}
7 changes: 6 additions & 1 deletion cmd/chart-scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"github.com/chartmuseum/storage"
)

func scan(backend storage.Backend, prefix string){
func check(backend storage.Backend) error {
_, err := backend.ListObjects("")
return err
}

func scan(backend storage.Backend, prefix string) {
objects, _ := backend.ListObjects(prefix)
for _, object := range objects {
fullPath := path.Join(prefix, object.Path)
Expand Down
91 changes: 91 additions & 0 deletions storage_fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package storage

// This file is a replacement for vendor/github.com/chartmuseum/storage/storage.go
// with a modified "objectPathIsInvalid" method (allows for recursion)

import (
"fmt"
"path/filepath"
"strings"
"time"
)

type (
// Object is a generic representation of a storage object
Object struct {
Path string
Content []byte
LastModified time.Time
}

// ObjectSliceDiff provides information on what has changed since last calling ListObjects
ObjectSliceDiff struct {
Change bool
Removed []Object
Added []Object
Updated []Object
}

// Backend is a generic interface for storage backends
Backend interface {
ListObjects(prefix string) ([]Object, error)
GetObject(path string) (Object, error)
PutObject(path string, content []byte) error
DeleteObject(path string) error
}
)

// HasExtension determines whether or not an object contains a file extension
func (object Object) HasExtension(extension string) bool {
return filepath.Ext(object.Path) == fmt.Sprintf(".%s", extension)
}

// GetObjectSliceDiff takes two objects slices and returns an ObjectSliceDiff
func GetObjectSliceDiff(os1 []Object, os2 []Object) ObjectSliceDiff {
var diff ObjectSliceDiff
for _, o1 := range os1 {
found := false
for _, o2 := range os2 {
if o1.Path == o2.Path {
found = true
if !o1.LastModified.Equal(o2.LastModified) {
diff.Updated = append(diff.Updated, o2)
}
break
}
}
if !found {
diff.Removed = append(diff.Removed, o1)
}
}
for _, o2 := range os2 {
found := false
for _, o1 := range os1 {
if o2.Path == o1.Path {
found = true
break
}
}
if !found {
diff.Added = append(diff.Added, o2)
}
}
diff.Change = len(diff.Removed)+len(diff.Added)+len(diff.Updated) > 0
return diff
}

func cleanPrefix(prefix string) string {
return strings.Trim(prefix, "/")
}

func removePrefixFromObjectPath(prefix string, path string) string {
if prefix == "" {
return path
}
path = strings.Replace(path, fmt.Sprintf("%s/", prefix), "", 1)
return path
}

func objectPathIsInvalid(path string) bool {
return path == ""
}
21 changes: 4 additions & 17 deletions vendor/github.com/chartmuseum/storage/storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54a5d09

Please sign in to comment.