-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
- Loading branch information
Showing
5 changed files
with
113 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == "" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.