-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fail when path is not a directory for peercontainer upload/download #1028
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) | ||
Comment on lines
+200
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashokponkumar would it be a good idea to support files as well as directories? Right now, this PR just raises an error if files are passed to upload. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
cengine, err := container.GetContainerEngine(false) | ||
if err != nil { | ||
return envpath, fmt.Errorf("failed to get the container engine. Error: %w", err) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to support only directories? Or is our current implementation support only directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashokponkumar From what I understand, I think it is for directories as of now. If you see the containerized transformer code, we actually create a tmp folder to upload the input json.
Having the upload and download path to include files would be a good flexibility to have.