Skip to content

Commit

Permalink
typof fix and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Aug 30, 2024
1 parent d7c2fd2 commit 0a78cf0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
*.zip
/*.sh
cmd/bali/bali
/bali
*.rpm
/dest/
22 changes: 21 additions & 1 deletion pkg/barrow/deb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package barrow

import "context"
import (
"context"
"fmt"
"time"

"github.com/balibuild/bali/v3/module/ar"
)

var (
debianArchList = map[string]string{
Expand All @@ -23,6 +29,20 @@ func debianArchName(arch string) string {
return arch
}

func addArFile(w ar.Writer, name string, body []byte, date time.Time) error {
header := &ar.Header{
Name: ToNixPath(name),
Size: int64(len(body)),
Mode: 0o644,
ModTime: date,
}
if err := w.WriteHeader(header); err != nil {
return fmt.Errorf("cannot write file header: %w", err)
}
_, err := w.Write(body)
return err
}

func (b *BarrowCtx) deb(ctx context.Context, p *Package, crates []*Crate) error {
select {
case <-ctx.Done():
Expand Down
9 changes: 9 additions & 0 deletions pkg/barrow/misc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package barrow

import (
"io"
"os"
"path/filepath"
"strings"
Expand All @@ -17,6 +18,14 @@ func isSymlink(fi os.FileInfo) bool {
return fi.Mode()&os.ModeSymlink != 0
}

// nopCloser wrap io.Writer --> io.WriteCloser
type nopCloser struct {
io.Writer
}

func (w nopCloser) Close() error {
return nil
}

// ToNixPath, AsExplicitRelativePath, AsRelativePath (MIT License)
// Thanks: https://github.com/goreleaser/nfpm/blob/main/files/files.go
Expand Down
12 changes: 2 additions & 10 deletions pkg/barrow/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ func (b *BarrowCtx) sh(ctx context.Context, p *Package, crates []*Crate) error {
return nil
}

type noWriteCloser struct {
io.Writer
}

func (w noWriteCloser) Close() error {
return nil
}

type FnCompressor func(w io.Writer) (io.WriteCloser, error)

func tarCompressor(method string) (FnCompressor, string, error) {
Expand All @@ -203,10 +195,10 @@ func tarCompressor(method string) (FnCompressor, string, error) {
}, ".tar.gz", nil
case "none":
return func(w io.Writer) (io.WriteCloser, error) {
return &noWriteCloser{Writer: w}, nil
return &nopCloser{Writer: w}, nil
}, ".tar", nil
default:
return nil, "", fmt.Errorf("unsupported zip compress method '%s'", method)
return nil, "", fmt.Errorf("unsupported tar compress method '%s'", method)
}
}

Expand Down

0 comments on commit 0a78cf0

Please sign in to comment.