Skip to content

Commit

Permalink
fix: fail when path is not a director for peercontainer upload
Browse files Browse the repository at this point in the history
Signed-off-by: Mehant Kammakomati <[email protected]>
  • Loading branch information
kmehant committed Apr 25, 2023
1 parent 2ababfc commit 0c509dc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions environment/peercontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func (e *PeerContainer) Destroy() error {

// Download downloads the path to outside the environment
func (e *PeerContainer) Download(path string) (string, error) {
fileInfo, err := e.Stat(path)
if err != nil {
return path, fmt.Errorf("failed to stat the given path : %s. Error: %v", path, err)
}
if !fileInfo.IsDir() {
return path, fmt.Errorf("download only supports directory paths. The path provided is %s. Error: %v", path, err)
}
output, err := os.MkdirTemp(e.TempPath, "*")
if err != nil {
return path, fmt.Errorf("failed to create temp dir. Error: %w", err)
Expand All @@ -186,6 +193,13 @@ func (e *PeerContainer) Download(path string) (string, error) {
// Upload uploads the path from outside the environment into it
func (e *PeerContainer) Upload(outpath string) (string, error) {
envpath := "/var/tmp/" + uniuri.NewLen(5) + "/" + filepath.Base(outpath)
fileInfo, err := os.Stat(outpath)
if err != nil {
return envpath, fmt.Errorf("failed to stat the given path : %s. Error: %v", outpath, err)
}
if !fileInfo.IsDir() {
return envpath, fmt.Errorf("upload only supports directory paths. The path provided is %s. Error: %v", outpath, err)
}
cengine, err := container.GetContainerEngine(false)
if err != nil {
return envpath, fmt.Errorf("failed to get the container engine. Error: %w", err)
Expand Down

0 comments on commit 0c509dc

Please sign in to comment.