Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: include subdirectories in example templates#1715

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dwahler merged 5 commits intomainfromdavid/1669-example-subdirs
May 25, 2022

Conversation

dwahler
Copy link
Contributor

This PR makescoder templates init correctly include files in subdirectories of examples.

Subtasks

  • moved example templates toexamples/templates and updated package to embed that entire directory
  • fixedexamples.Archive to recursively walk directories
  • added test to make sure tar headers are written for both files and directories
  • updated documentation links

Fixes#1669

@dwahlerdwahler requested a review froma teamMay 24, 2022 17:11
Comment on lines 172 to 175
_, err = tarWriter.Write(data)
if err != nil {
return xerrors.Errorf("write: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to io.Copy instead to avoid the extra buffer

if err != nil {
return xerrors.Errorf("open file %s: %w", path, err)
}
_, err = file.Read(data)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't matter if you use io.Copy, but in the future you should use io.ReadAll instead, because Read isn't guaranteed to fill your output buffer

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good catch!

@@ -154,22 +155,17 @@ func Archive(exampleID string) ([]byte, error) {
} else {
header.Name = path

data := make([]byte, info.Size())
file, err := exampleFiles.Open(path)
if err != nil {
return xerrors.Errorf("open file %s: %w", path, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Should be closed i.e.defer file.Close()

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good point. Technically I think we would be OK without it, because the readers returned byembed.FS are just pointers, but I added it anyway to make the code more obviously correct.

deansheather reacted with thumbs up emoji
@dwahlerdwahler merged commitf8410de intomainMay 25, 2022
@dwahlerdwahler deleted the david/1669-example-subdirs branchMay 25, 2022 15:34
@dwahlerdwahler mentioned this pull requestJun 10, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@deansheatherdeansheatherdeansheather approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: subfolders in example templates are not bundled
3 participants
@dwahler@johnstcn@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp