Skip to content

Commit

Permalink
github/workflows, testdata, smol bug squashes
Browse files Browse the repository at this point in the history
  • Loading branch information
frantjc committed Jun 2, 2022
1 parent c67c22d commit f2fb06c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches:
- main
permissions:
contents: read
packages: write
jobs:
build-push:
runs-on: ubuntu-latest
steps:
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v2
with:
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ INSTALL ?= sudo install
.DEFAULT: install

install: binaries
@$(INSTALL) $(CURDIR)/bin/sqncd $(CURDIR)/bin/addendum $(BIN)
@$(INSTALL) $(CURDIR)/bin/addendum $(BIN)

bins binaries: addendum
bin bins binaries: addendum

addendum:
@$(GO) build -ldflags "-s -w -X $(MODULE).Version=$(VERSION) -X $(MODULE).Prerelease=$(PRERELEASE)" -o $(CURDIR)/bin $(CURDIR)/cmd/$@
Expand All @@ -40,12 +40,12 @@ fmt vet test:
tidy vendor verify:
@$(GO) mod $@

clean:
@rm -rf bin/*

.PHONY: \
install bins binaries sqnc sqncd \
shims shimuses shimsource uses source placeholders \
install bin bins binaries addendum \
image img \
fmt vet test \
tidy vendor verify \
clean \
protos \
lint tools
clean
31 changes: 22 additions & 9 deletions cmd/addendum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
)
rootCmd.Flags().BoolVar(&rm, "rm", false, "Remove the tarball after extracting its contents")
rootCmd.Flags().StringVarP(&out, "out", "o", ".", "Where to extract the tarball's contents to")
rootCmd.Flags().BoolVar(&gz, "gzip", false, "Force assuming the tarball is gzipped")
rootCmd.Flags().BoolVar(&gz, "gz", false, "Force assuming the tarball is gzipped")
}

func run(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -64,25 +64,38 @@ func run(cmd *cobra.Command, args []string) error {

tarball := tar.NewReader(r)

if rm {
defer os.Remove(path)
}

for {
header, err := tarball.Next()
switch {
case err == io.EOF:
if rm {
return os.Remove(path)
}

return nil
case err != nil:
return err
}

fullpath := filepath.Join(path, header.Name)
fullpath, err := filepath.Abs(
filepath.Join(out, header.Name),
)
if err != nil {
return fmt.Errorf("unable to determine path for tar header %s", header.Name)
}

switch header.Typeflag {
case tar.TypeDir:
if err := os.Mkdir(fullpath, header.FileInfo().Mode().Perm()); err != nil {
return fmt.Errorf("unable to create directory %s", fullpath)
di, err := os.Stat(fullpath)
switch {
case err == nil && !di.IsDir():
return fmt.Errorf("not a directory %s", fullpath)
case err == nil && di.IsDir():
// nothing to do
default:
if err := os.Mkdir(fullpath, header.FileInfo().Mode().Perm()); err != nil {
return fmt.Errorf("unable to create directory %s", fullpath)
}
}
case tar.TypeReg:
o, err := os.Create(fullpath)
Expand All @@ -92,7 +105,7 @@ func run(cmd *cobra.Command, args []string) error {
defer o.Close()

if _, err := io.CopyN(o, tarball, header.Size); err != nil {
return fmt.Errorf("unable to copy to file %s", fullpath)
return fmt.Errorf("unable to write to file %s", fullpath)
}
default:
return fmt.Errorf("unable to handle tar header type %b", header.Typeflag)
Expand Down
Binary file added testdata/zip_3.0_x86_64_not_a.tar
Binary file not shown.

0 comments on commit f2fb06c

Please sign in to comment.