Skip to content

Commit

Permalink
Merge pull request #24 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.4.0
  • Loading branch information
andyone authored Apr 26, 2023
2 parents f9dc922 + 854cd4e commit fefdb71
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
parallel-finished: true

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check spelling
uses: crate-ci/typos@master
Binary file added .testdata/data-cpio.tar
Binary file not shown.
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[files]
extend-exclude = ["go.sum"]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ package main

import (
"fmt"

"github.com/essentialkaos/npck/tgz"
"github.com/essentialkaos/npck"
)

func main() {
err := tgz.Unpack("file.tar.gz", "/home/john")
err := npck.Unpack("file.tar.gz", "/home/john")

if err != nil {
panic("Can't unpack file: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.19
require (
github.com/cyphar/filepath-securejoin v0.2.3
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/ek/v12 v12.64.0
github.com/klauspost/compress v1.16.4
github.com/essentialkaos/ek/v12 v12.64.1
github.com/klauspost/compress v1.16.5
github.com/pierrec/lz4/v4 v4.1.17
github.com/ulikunitz/xz v0.5.11
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0=
github.com/essentialkaos/ek/v12 v12.64.0 h1:5HgBltCfY4uwsSFSv+yVBns6UIzXbiNEE31kcm/0UyA=
github.com/essentialkaos/ek/v12 v12.64.0/go.mod h1:9MlSuHpewu7OZ9tM9dLFHvoA8dflBIUPCA0Ctt97wRs=
github.com/klauspost/compress v1.16.4 h1:91KN02FnsOYhuunwU4ssRe8lc2JosWmizWa91B5v1PU=
github.com/klauspost/compress v1.16.4/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/essentialkaos/ek/v12 v12.64.1 h1:XjIF4GHCgVIY0S0KEz8g1OrNrRoHGU+vAUXSYIKNIbI=
github.com/essentialkaos/ek/v12 v12.64.1/go.mod h1:PFJckNu+x4mHqsjndUeYRDPgDgvZEgcjpy1RpCYtx4g=
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
11 changes: 11 additions & 0 deletions tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ func createDir(h *tar.Header, path string) error {

// createFile creates new file
func createFile(h *tar.Header, r io.Reader, path string) error {
dir := filepath.Dir(path)
_, err := os.Stat(dir)

if os.IsNotExist(err) {
err := os.MkdirAll(dir, 0755)

if err != nil {
return err
}
}

fd, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, h.FileInfo().Mode())

if err != nil {
Expand Down
38 changes: 25 additions & 13 deletions tar/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,46 @@ func Test(t *testing.T) { TestingT(t) }

// ////////////////////////////////////////////////////////////////////////////////// //

type TarSuite struct {
Dir string
}
type TarSuite struct{}

var _ = Suite(&TarSuite{})

// ////////////////////////////////////////////////////////////////////////////////// //

func (s *TarSuite) SetUpSuite(c *C) {
s.Dir = c.MkDir()
func (s *TarSuite) TestUnpack(c *C) {
dir := c.MkDir()
err := Unpack("../.testdata/data.tar", dir)

c.Assert(err, IsNil)

c.Assert(fsutil.IsExist(dir+"/data"), Equals, true)
c.Assert(fsutil.GetMode(dir+"/data"), Equals, os.FileMode(0700))

c.Assert(fsutil.IsExist(dir+"/data/payload.txt"), Equals, true)
c.Assert(fsutil.GetMode(dir+"/data/payload.txt"), Equals, os.FileMode(0644))

c.Assert(hash.FileHash(dir+"/data/payload.txt"), Equals, "918c03a211adc19a466c9db22efa575efb6c488fd41c70e57b1ec0920f1a1d8c")
}

func (s *TarSuite) TestUnpack(c *C) {
err := Unpack("../.testdata/data.tar", s.Dir)
func (s *TarSuite) TestCPIOUnpack(c *C) {
dir := c.MkDir()
err := Unpack("../.testdata/data-cpio.tar", dir)

c.Assert(err, IsNil)

c.Assert(fsutil.IsExist(s.Dir+"/data"), Equals, true)
c.Assert(fsutil.GetMode(s.Dir+"/data"), Equals, os.FileMode(0700))
c.Assert(fsutil.IsExist(dir+"/data"), Equals, true)
c.Assert(fsutil.GetMode(dir+"/data"), Equals, os.FileMode(0755))

c.Assert(fsutil.IsExist(s.Dir+"/data/payload.txt"), Equals, true)
c.Assert(fsutil.GetMode(s.Dir+"/data/payload.txt"), Equals, os.FileMode(0644))
c.Assert(fsutil.IsExist(dir+"/data/payload.txt"), Equals, true)
c.Assert(fsutil.GetMode(dir+"/data/payload.txt"), Equals, os.FileMode(0644))

c.Assert(hash.FileHash(s.Dir+"/data/payload.txt"), Equals, "918c03a211adc19a466c9db22efa575efb6c488fd41c70e57b1ec0920f1a1d8c")
c.Assert(hash.FileHash(dir+"/data/payload.txt"), Equals, "918c03a211adc19a466c9db22efa575efb6c488fd41c70e57b1ec0920f1a1d8c")
}

func (s *TarSuite) TestErrors(c *C) {
err := Unpack("../.testdata/unknown.tar", s.Dir)
dir := c.MkDir()

err := Unpack("../.testdata/unknown.tar", dir)
c.Assert(err, NotNil)

err = Unpack("../.testdata/data.tar", "/unknown")
Expand Down

0 comments on commit fefdb71

Please sign in to comment.