gruntwork-io / fetch

Download files, folders, and release assets from a specific git commit, branch, or tag of public and private GitHub repos.
https://www.gruntwork.io/
MIT License
589 stars 90 forks source link

Fix to ensure specifying source-path does not download unwanted files #56

Closed vedala closed 5 years ago

vedala commented 5 years ago

This PR fixes issue #37 .

The extractFiles function needed a very simple change to fix this issue. Since source-path specifies a folder, appending a "/" to pathPrefix variable makes sure that we download only files from within the folder specified in source-path.

I also added a zip file to test-fixtures folder which ensures that the test scenario specified in the issue description is tested.

vedala commented 5 years ago

@brikis98 thanks for your comments.

I agree that appending a literal "/" could be highly OS/platform dependent.

I will work on finding a solution based on your suggestion - converting f.name and pathPrefix to canonical paths and comparing them.

vedala commented 5 years ago

Also wanted to respond to your comment about trailing slash being present in the --source-path arg.

In the line just above the line I added, the call to filepath.Join() removes any trailing slashes. I thought I would quickly mention.

vedala commented 5 years ago

I updated the code to what I believe handles all cases now.

I am using continue to skip specific cases in for loop instead of using a if check. I felt this resulted in simpler if conditions. I also retained the original indentation so that unmodified code does not show up in diff.

Please see the comments in code for an explanation how I check for each case.

brikis98 commented 5 years ago

Tests passed. Merging.

brikis98 commented 5 years ago

https://github.com/gruntwork-io/fetch/releases/tag/v0.3.7

vedala commented 5 years ago

Thanks!