Skip to content
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

Feature/file.fetch #543

Merged
merged 1 commit into from
Dec 16, 2016
Merged

Feature/file.fetch #543

merged 1 commit into from
Dec 16, 2016

Conversation

arichardet
Copy link
Contributor

Add file.fetch module:

  • provide file path or url as source
  • fetch with or without checksum
  • includes a "force" option to replace the file if is already exists

Copy link
Contributor

@rebeccaskinner rebeccaskinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nit-pick errors and questions

status = resource.NewStatus()
)

if !f.hasApplied {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do if f.hasApplied { return status, nil } here instead to reduce nesting of the rest of the code?

stat, err := f.DiffFile(status, hsh)
if err != nil {
return stat, err
} else if resource.AnyChanges(stat.Differences) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an option here to do else if !resource.AnyChanges(state.Differences) { return status, nil }?

status.AddMessage("fetched successfully")
f.hasApplied = true
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it might be worth it here to actually set f.Hash even if the user hadn't originally specified one- the idea being that someone might want to do a lookup on the hash of a fetched file even if they didn't actually specify an explicit one. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't actually do this without knowing the hash type (md5, sha1, etc.).

}

if p.Hash != nil {
if strings.TrimSpace(*p.Hash) == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth actually checking the length of the string here to make sure it's the right length for a hash of the specified type?

@rebeccaskinner
Copy link
Contributor

LGTM after vendor fixing and rebasing on #533

@BrianHicks BrianHicks merged commit 7104e68 into master Dec 16, 2016
@BrianHicks BrianHicks deleted the feature/file.fetch branch December 16, 2016 21:51
BrianHicks added a commit that referenced this pull request Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants