-
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
4 changed files
with
62 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
// Needed in order to scan directories for local filesystem backend | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/chartmuseum/storage" | ||
) | ||
|
||
type LocalFilesystemBackendWithDir struct { | ||
*storage.LocalFilesystemBackend | ||
} | ||
|
||
func (b LocalFilesystemBackendWithDir) ListObjects(prefix string) ([]storage.Object, error) { | ||
var objects []storage.Object | ||
files, err := ioutil.ReadDir(path.Join(b.RootDirectory, prefix)) | ||
if err != nil { | ||
if os.IsNotExist(err) { // OK if the directory doesnt exist yet | ||
err = nil | ||
} | ||
return objects, err | ||
} | ||
for _, f := range files { | ||
object := storage.Object{Path: f.Name(), Content: []byte{}, LastModified: f.ModTime()} | ||
objects = append(objects, object) | ||
} | ||
return objects, nil | ||
} | ||
|
||
// NewLocalFilesystemBackendWithDir creates a new instance of LocalFilesystemBackendWithDir | ||
func NewLocalFilesystemBackendWithDir(rootDirectory string) *LocalFilesystemBackendWithDir { | ||
absPath, err := filepath.Abs(rootDirectory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
localFsBackend := &storage.LocalFilesystemBackend{RootDirectory: absPath} | ||
b := &LocalFilesystemBackendWithDir{localFsBackend} | ||
return b | ||
} |
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