From e75f16d4490aab056a0db2085dd4834b14cd86e4 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Thu, 25 May 2017 22:50:29 +0200 Subject: [PATCH 01/11] Move config test to other test-file, add priority and section to config --- config.go | 4 ++++ config_test.go | 39 +++++++++++++++++++++++++++++++++++++++ debpkg_test.go | 36 ------------------------------------ 3 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 config_test.go diff --git a/config.go b/config.go index 341fead..21c3ee5 100644 --- a/config.go +++ b/config.go @@ -18,6 +18,8 @@ type debPkgSpecFileCfg struct { Maintainer string `yaml:"maintainer"` MaintainerEmail string `yaml:"maintainer_email"` Homepage string `yaml:"homepage"` + Section string `yaml:"section"` + Priority string `yaml:"priority"` Description struct { Short string `yaml:"short"` Long string `yaml:"long"` @@ -44,6 +46,8 @@ func (deb *DebPkg) Config(filename string) error { return err } + deb.SetSection(cfg.Section) + deb.SetPriority(Priority(cfg.Priority)) deb.SetName(cfg.Name) deb.SetVersion(cfg.Version) deb.SetArchitecture(cfg.Architecture) diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..9030851 --- /dev/null +++ b/config_test.go @@ -0,0 +1,39 @@ +package debpkg + +import "testing" + +// TestConfig verifies the specfile is correctly loaded +func TestConfig(t *testing.T) { + deb := New() + + err := deb.Config("debpkg.yml") + if err != nil { + t.Errorf("Unable to open debpkg.yml in CWD: %v", err) + return + } + + if deb.control.info.version.full != "7.6.5" { + t.Errorf("Unexpected deb.control.info.version.full: %s", deb.control.info.version.full) + return + } + + if deb.control.info.maintainer != "Foo Bar" { + t.Errorf("Unexpected deb.control.info.maintainer: %s", deb.control.info.maintainer) + return + } + + if deb.control.info.maintainerEmail != "foo@bar.com" { + t.Errorf("Unexpected deb.control.info.maintainerEmail: %s", deb.control.info.maintainerEmail) + return + } + + if deb.control.info.homepage != "https://github.com/xor-gate/debpkg" { + t.Errorf("Unexpected deb.control.info.homepage: %s", deb.control.info.homepage) + return + } + + if deb.control.info.descrShort != "This is a short description" { + t.Error("Unexpected short description") + return + } +} diff --git a/debpkg_test.go b/debpkg_test.go index d892d4c..51ade02 100644 --- a/debpkg_test.go +++ b/debpkg_test.go @@ -19,42 +19,6 @@ func init() { e, _ = openpgp.NewEntity("Foo Bar", "", "foo@bar.com", nil) } -// TestConfig verifies the specfile is correctly loaded -func TestConfig(t *testing.T) { - deb := New() - - err := deb.Config("debpkg.yml") - if err != nil { - t.Errorf("Unable to open debpkg.yml in CWD: %v", err) - return - } - - if deb.control.info.version.full != "7.6.5" { - t.Errorf("Unexpected deb.control.info.version.full: %s", deb.control.info.version.full) - return - } - - if deb.control.info.maintainer != "Foo Bar" { - t.Errorf("Unexpected deb.control.info.maintainer: %s", deb.control.info.maintainer) - return - } - - if deb.control.info.maintainerEmail != "foo@bar.com" { - t.Errorf("Unexpected deb.control.info.maintainerEmail: %s", deb.control.info.maintainerEmail) - return - } - - if deb.control.info.homepage != "https://github.com/xor-gate/debpkg" { - t.Errorf("Unexpected deb.control.info.homepage: %s", deb.control.info.homepage) - return - } - - if deb.control.info.descrShort != "This is a short description" { - t.Error("Unexpected short description") - return - } -} - // Test creation of empty digest func TestDigestCreateEmpty(t *testing.T) { // FIXME it seems whe digesting the data buf the whole tarball will go corrupt... From 73f05c7763d69854734b1126eac5af6f6594c45d Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Thu, 25 May 2017 23:03:55 +0200 Subject: [PATCH 02/11] Add defaults, cleanup test --- config.go | 15 ++++++++++++--- config_test.go | 15 ++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/config.go b/config.go index 21c3ee5..c0034e6 100644 --- a/config.go +++ b/config.go @@ -34,18 +34,27 @@ type debPkgSpecFileCfg struct { // Config loads settings from a depkg.yml specfile func (deb *DebPkg) Config(filename string) error { - cfg := debPkgSpecFileCfg{} + cfg := debPkgSpecFileCfg{ + Name: "unknown", + Version: "0.1.0+dev", + Architecture: "any", + Maintainer: "anonymous", + MaintainerEmail: "anon@foo.bar", + Homepage: "https://www.google.com", + Section: "misc", + Priority: string(PriorityOptional), + } + cfg.Description.Long = "-" + cfg.Description.Short = "-" cfgFile, err := ioutil.ReadFile(filename) if err != nil { return err } - err = yaml.Unmarshal(cfgFile, &cfg) if err != nil { return err } - deb.SetSection(cfg.Section) deb.SetPriority(Priority(cfg.Priority)) deb.SetName(cfg.Name) diff --git a/config_test.go b/config_test.go index 9030851..e39fa2d 100644 --- a/config_test.go +++ b/config_test.go @@ -2,38 +2,27 @@ package debpkg import "testing" -// TestConfig verifies the specfile is correctly loaded -func TestConfig(t *testing.T) { +// TestExampleConfig verifies if the config example in the root is correctly loaded +func TestExampleConfig(t *testing.T) { deb := New() err := deb.Config("debpkg.yml") if err != nil { t.Errorf("Unable to open debpkg.yml in CWD: %v", err) - return } - if deb.control.info.version.full != "7.6.5" { t.Errorf("Unexpected deb.control.info.version.full: %s", deb.control.info.version.full) - return } - if deb.control.info.maintainer != "Foo Bar" { t.Errorf("Unexpected deb.control.info.maintainer: %s", deb.control.info.maintainer) - return } - if deb.control.info.maintainerEmail != "foo@bar.com" { t.Errorf("Unexpected deb.control.info.maintainerEmail: %s", deb.control.info.maintainerEmail) - return } - if deb.control.info.homepage != "https://github.com/xor-gate/debpkg" { t.Errorf("Unexpected deb.control.info.homepage: %s", deb.control.info.homepage) - return } - if deb.control.info.descrShort != "This is a short description" { t.Error("Unexpected short description") - return } } From 7add71124053ead939ea2649205e2f4e408991d0 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 19:32:56 +0200 Subject: [PATCH 03/11] Add test for default configuration, more checking of demo-config, also improve the demo-config --- config.go | 6 +++- config_test.go | 76 ++++++++++++++++++++++++++++++++++++++++---------- debpkg.yml | 7 ++++- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/config.go b/config.go index c0034e6..8b8792c 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -// Copyright 2016 Jerry Jacobs. All rights reserved. +// Copyright 2017 Jerry Jacobs & Rik van der Heijden. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. @@ -7,6 +7,7 @@ package debpkg import ( "fmt" "io/ioutil" + "runtime" yaml "gopkg.in/yaml.v2" ) @@ -20,6 +21,7 @@ type debPkgSpecFileCfg struct { Homepage string `yaml:"homepage"` Section string `yaml:"section"` Priority string `yaml:"priority"` + BuiltUsing string `yaml:"built_using"` Description struct { Short string `yaml:"short"` Long string `yaml:"long"` @@ -43,6 +45,7 @@ func (deb *DebPkg) Config(filename string) error { Homepage: "https://www.google.com", Section: "misc", Priority: string(PriorityOptional), + BuiltUsing: runtime.Version(), } cfg.Description.Long = "-" cfg.Description.Short = "-" @@ -65,6 +68,7 @@ func (deb *DebPkg) Config(filename string) error { deb.SetHomepage(cfg.Homepage) deb.SetShortDescription(cfg.Description.Short) deb.SetDescription(cfg.Description.Long) + deb.SetBuiltUsing(cfg.BuiltUsing) for _, file := range cfg.Files { err := deb.AddFile(file.Src, file.Dest) diff --git a/config_test.go b/config_test.go index e39fa2d..027a158 100644 --- a/config_test.go +++ b/config_test.go @@ -1,6 +1,12 @@ package debpkg -import "testing" +import ( + "io/ioutil" + "runtime" + "testing" + + "github.com/stretchr/testify/assert" +) // TestExampleConfig verifies if the config example in the root is correctly loaded func TestExampleConfig(t *testing.T) { @@ -10,19 +16,61 @@ func TestExampleConfig(t *testing.T) { if err != nil { t.Errorf("Unable to open debpkg.yml in CWD: %v", err) } - if deb.control.info.version.full != "7.6.5" { - t.Errorf("Unexpected deb.control.info.version.full: %s", deb.control.info.version.full) - } - if deb.control.info.maintainer != "Foo Bar" { - t.Errorf("Unexpected deb.control.info.maintainer: %s", deb.control.info.maintainer) - } - if deb.control.info.maintainerEmail != "foo@bar.com" { - t.Errorf("Unexpected deb.control.info.maintainerEmail: %s", deb.control.info.maintainerEmail) - } - if deb.control.info.homepage != "https://github.com/xor-gate/debpkg" { - t.Errorf("Unexpected deb.control.info.homepage: %s", deb.control.info.homepage) + assert.Equal(t, "7.6.5", deb.control.info.version.full, + "Unexpected deb.control.info.version.full") + assert.Equal(t, "Foo Bar", deb.control.info.maintainer, + "Unexpected deb.control.info.maintainer") + assert.Equal(t, "foo@bar.com", deb.control.info.maintainerEmail, + "Unexpected deb.control.info.maintainerEmail") + assert.Equal(t, "https://github.com/xor-gate/debpkg", deb.control.info.homepage, + "Unexpected deb.control.info.homepage") + assert.Equal(t, "This is a short description", deb.control.info.descrShort, + "Unexpected short description") + assert.Equal(t, "golang", deb.control.info.builtUsing, + "unexpected built using") + assert.Equal(t, "devel", deb.control.info.section, + "unexpected section") + assert.Equal(t, PriorityStandard, deb.control.info.priority, + "unexpected priority") +} + +func TestDefaultConfig(t *testing.T) { + f, err := ioutil.TempFile("", "config") + if err != nil { + t.Errorf("unexpected error creating tempfile: %v", err) } - if deb.control.info.descrShort != "This is a short description" { - t.Error("Unexpected short description") + f.Close() + deb := New() + if err := deb.Config(f.Name()); err != nil { + t.Errorf("Unexpected error during load of empty config: %v", err) } + assert.Equal(t, "any", deb.control.info.architecture, + "unexpected architecture") + assert.Equal(t, "anonymous", deb.control.info.maintainer, + "unexpected maintainer") + assert.Equal(t, "anon@foo.bar", deb.control.info.maintainerEmail, + "unexpected maintainer email") + assert.Equal(t, "https://www.google.com", deb.control.info.homepage, + "unexpected homepage") + assert.Equal(t, PriorityOptional, deb.control.info.priority, + "unexpected priority") + assert.Equal(t, "0.1.0+dev", deb.control.info.version.full, + "unexpected version") + assert.Equal(t, "misc", deb.control.info.section, + "unexpected section") + assert.Equal(t, "unknown", deb.control.info.name, + "unexpected name") + assert.Equal(t, runtime.Version(), deb.control.info.builtUsing, + "unexpected built using") + assert.Equal(t, "-", deb.control.info.descrShort, + "unexpected short description") + assert.Equal(t, " -", deb.control.info.descr, + "unexpected long description") + + /* + deb.control.info.conflicts + deb.control.info.provides + deb.control.info.replaces + deb.control.info.suggests + vcs**/ } diff --git a/debpkg.yml b/debpkg.yml index ea9584c..61b8168 100644 --- a/debpkg.yml +++ b/debpkg.yml @@ -1,5 +1,5 @@ ## -# Copyright 2017 Jerry Jacobs. All rights reserved. +# Copyright 2017 Jerry Jacobs & Rik van der Heijden. All rights reserved. # Use of this source code is governed by the MIT # license that can be found in the LICENSE file. # @@ -11,6 +11,9 @@ architecture: all maintainer: Foo Bar maintainer_email: foo@bar.com homepage: https://github.com/xor-gate/debpkg +section: devel +priority: standard +built_using: golang description: short: This is a short description long: > @@ -25,5 +28,7 @@ files: - file: cmd/debpkg/main.go dest: /tmp/main.go - file: README.md +directories: + - vendor emptydirs: - /tmp/bogus/directory \ No newline at end of file From be1ceeb8dbc5ad026e2a5be653e98d0108a1e156 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 19:37:29 +0200 Subject: [PATCH 04/11] Make config-reading more strict, also add test for non-existing config-file --- config.go | 10 +++++----- config_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/config.go b/config.go index 8b8792c..f86d825 100644 --- a/config.go +++ b/config.go @@ -52,11 +52,11 @@ func (deb *DebPkg) Config(filename string) error { cfgFile, err := ioutil.ReadFile(filename) if err != nil { - return err + return fmt.Errorf("problem reading config file: %v", err) } err = yaml.Unmarshal(cfgFile, &cfg) if err != nil { - return err + return fmt.Errorf("problem unmarshaling config file: %v", err) } deb.SetSection(cfg.Section) deb.SetPriority(Priority(cfg.Priority)) @@ -73,21 +73,21 @@ func (deb *DebPkg) Config(filename string) error { for _, file := range cfg.Files { err := deb.AddFile(file.Src, file.Dest) if err != nil { - fmt.Printf("error adding file %s: %v\n", file.Src, err) + return fmt.Errorf("error adding file %s: %v", file.Src, err) } } for _, dir := range cfg.Directories { err := deb.AddDirectory(dir) if err != nil { - fmt.Printf("error adding directory %s: %v\n", dir, err) + return fmt.Errorf("error adding directory %s: %v", dir, err) } } for _, dir := range cfg.EmptyDirectories { err := deb.AddEmptyDirectory(dir) if err != nil { - fmt.Printf("error adding directory %s: %v\n", dir, err) + return fmt.Errorf("error adding directory %s: %v", dir, err) } } diff --git a/config_test.go b/config_test.go index 027a158..f303024 100644 --- a/config_test.go +++ b/config_test.go @@ -66,11 +66,11 @@ func TestDefaultConfig(t *testing.T) { "unexpected short description") assert.Equal(t, " -", deb.control.info.descr, "unexpected long description") +} + +func TestNonExistingConfig(t *testing.T) { + deb := New() - /* - deb.control.info.conflicts - deb.control.info.provides - deb.control.info.replaces - deb.control.info.suggests - vcs**/ + err := deb.Config("/non/existant/config/file") + assert.Error(t, err, "error expected") } From 7abb6dd111fb8e259b4dd80b73f09fb919604003 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 19:41:12 +0200 Subject: [PATCH 05/11] Add missing package for tests --- .appveyor.yml | 1 + .travis.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 3dd9679..39546c9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,4 +8,5 @@ build_script: - cmd: go get -v github.com/xor-gate/debpkg/... - cmd: go build github.com/xor-gate/debpkg test_script: +- cmd: go get github.com/stretchr/testify/assert - cmd: go test -v -race github.com/xor-gate/debpkg diff --git a/.travis.yml b/.travis.yml index 856b8f3..774a20f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ go: before_install: - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls + - go get github.com/stretchr/testify/assert - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi script: From 57e3ba73531bb878832b005d52e599ddf8ec1f77 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:34:19 +0200 Subject: [PATCH 06/11] Add AUTHORS file and rework copyright headers --- AUTHORS | 2 ++ LICENSE | 2 +- README.md | 1 - ar.go | 5 +++-- config.go | 2 +- config_test.go | 4 ++++ constants.go | 4 ++++ control.go | 13 +++++++------ control_test.go | 2 +- data.go | 9 +++++---- debpkg.go | 13 +++++++------ debpkg.yml | 2 +- debpkg_test.go | 7 ++++--- digest.go | 8 ++++---- doc.go | 2 +- lib/targzip/targz.go | 14 +++++++------- 16 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..7faa06d --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Jerry Jacobs (@xor-gate) +Rik van der Heijden (@rikvdh) \ No newline at end of file diff --git a/LICENSE b/LICENSE index 17756d7..2926711 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Jerry Jacobs +Copyright (c) 2016-2017 Debpkg authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1f8f24b..4b9abe3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ The feature list below describes the usability state of the project: - Unable to specifiy file or folder destination when adding - ## Why this package was created This package was created due to the lack to debianize from other platforms (windows/mac/*bsd). Because diff --git a/ar.go b/ar.go index ffb230c..6acbb60 100644 --- a/ar.go +++ b/ar.go @@ -1,13 +1,14 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. package debpkg import ( - "time" "fmt" "os" + "time" + "github.com/blakesmith/ar" ) diff --git a/config.go b/config.go index f86d825..c0b9c3c 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -// Copyright 2017 Jerry Jacobs & Rik van der Heijden. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. diff --git a/config_test.go b/config_test.go index f303024..0f62a9a 100644 --- a/config_test.go +++ b/config_test.go @@ -1,3 +1,7 @@ +// Copyright 2017 Debpkg authors. All rights reserved. +// Use of this source code is governed by the MIT +// license that can be found in the LICENSE file. + package debpkg import ( diff --git a/constants.go b/constants.go index 305e418..bb8b1aa 100644 --- a/constants.go +++ b/constants.go @@ -1,3 +1,7 @@ +// Copyright 2017 Debpkg authors. All rights reserved. +// Use of this source code is governed by the MIT +// license that can be found in the LICENSE file. + package debpkg // Priority for Debian package diff --git a/control.go b/control.go index 0c9d31e..a9e92a3 100644 --- a/control.go +++ b/control.go @@ -1,21 +1,22 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. package debpkg import ( - "strings" "bytes" "fmt" + "strings" + "github.com/xor-gate/debpkg/lib/targzip" ) type debPkgControl struct { - buf *bytes.Buffer - tgz *targzip.TarGzip - info debPkgControlInfo - extra []string // Extra files added to the control.tar.gz. Typical usage is for conffiles, postinst, postrm, prerm. + buf *bytes.Buffer + tgz *targzip.TarGzip + info debPkgControlInfo + extra []string // Extra files added to the control.tar.gz. Typical usage is for conffiles, postinst, postrm, prerm. conffiles []string // Conffiles which must be treated as configuration files } diff --git a/control_test.go b/control_test.go index 1ff5d81..ef48225 100644 --- a/control_test.go +++ b/control_test.go @@ -1,4 +1,4 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. diff --git a/data.go b/data.go index 32af67c..2f7170b 100644 --- a/data.go +++ b/data.go @@ -1,16 +1,17 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. package debpkg import ( - "io" + "bytes" + "crypto/md5" "fmt" + "io" "os" - "crypto/md5" - "bytes" "strings" + "github.com/xor-gate/debpkg/lib/targzip" ) diff --git a/debpkg.go b/debpkg.go index 6490cae..4750c10 100644 --- a/debpkg.go +++ b/debpkg.go @@ -1,4 +1,4 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "time" + "github.com/xor-gate/debpkg/lib/targzip" "golang.org/x/crypto/openpgp" @@ -20,10 +21,10 @@ import ( // DebPkg holds data for a single debian package type DebPkg struct { - debianBinary string - control debPkgControl - data debPkgData - digest debPkgDigest + debianBinary string + control debPkgControl + data debPkgData + digest debPkgDigest } // New creates new debian package @@ -129,7 +130,7 @@ func (deb *DebPkg) WriteSigned(filename string, entity *openpgp.Entity, keyid st // AddFile adds a file by filename to the package func (deb *DebPkg) AddFile(filename string, dest ...string) error { - return deb.data.addFile(filename, dest ...) + return deb.data.addFile(filename, dest...) } // AddEmptyDirectory adds a empty directory to the package diff --git a/debpkg.yml b/debpkg.yml index 61b8168..09e030f 100644 --- a/debpkg.yml +++ b/debpkg.yml @@ -1,5 +1,5 @@ ## -# Copyright 2017 Jerry Jacobs & Rik van der Heijden. All rights reserved. +# Copyright 2017 Debpkg authors. All rights reserved. # Use of this source code is governed by the MIT # license that can be found in the LICENSE file. # diff --git a/debpkg_test.go b/debpkg_test.go index 51ade02..4fd14c6 100644 --- a/debpkg_test.go +++ b/debpkg_test.go @@ -1,4 +1,4 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. @@ -8,8 +8,9 @@ import ( "fmt" "os/exec" "path/filepath" - "golang.org/x/crypto/openpgp" "testing" + + "golang.org/x/crypto/openpgp" ) var e *openpgp.Entity @@ -165,7 +166,7 @@ func ExampleWrite() { } func dpkg(cmd, action, filename string) error { - args := []string{"--"+action, filename} + args := []string{"--" + action, filename} if err := exec.Command(cmd, args...).Run(); err != nil { return err } diff --git a/digest.go b/digest.go index d626784..71e4f7f 100644 --- a/digest.go +++ b/digest.go @@ -1,17 +1,17 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. package debpkg import ( - "io" - "fmt" "bytes" - "hash" "crypto" "crypto/md5" "crypto/sha1" + "fmt" + "hash" + "io" ) const debPkgDigestDefaultHash = crypto.SHA1 diff --git a/doc.go b/doc.go index 47b15d3..3c9606e 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ -// Copyright 2016 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. diff --git a/lib/targzip/targz.go b/lib/targzip/targz.go index 32245d1..cb87436 100644 --- a/lib/targzip/targz.go +++ b/lib/targzip/targz.go @@ -1,18 +1,18 @@ -// Copyright 2017 Jerry Jacobs. All rights reserved. +// Copyright 2017 Debpkg authors. All rights reserved. // Use of this source code is governed by the MIT // license that can be found in the LICENSE file. package targzip import ( - "os" - "io" - "fmt" - "time" - "strings" "archive/tar" - "path/filepath" "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" + "strings" + "time" ) type TarGzip struct { From 17fdcd017a61ae59eac93f7c6a8f1ca8b06fbb34 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:35:46 +0200 Subject: [PATCH 07/11] Add missing comment --- lib/targzip/targz.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/targzip/targz.go b/lib/targzip/targz.go index cb87436..c1c7707 100644 --- a/lib/targzip/targz.go +++ b/lib/targzip/targz.go @@ -15,6 +15,7 @@ import ( "time" ) +// TarGzip is a combined writer for .tar.gz-alike files type TarGzip struct { tw *tar.Writer gw *gzip.Writer From 6397bb69f6cb09569ee84ecde4f6e00a0344b316 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:37:12 +0200 Subject: [PATCH 08/11] Fix some metalinter warnings --- debpkg.go | 9 +-------- debpkg_test.go | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/debpkg.go b/debpkg.go index 4750c10..234cd71 100644 --- a/debpkg.go +++ b/debpkg.go @@ -144,17 +144,10 @@ func (deb *DebPkg) AddDirectory(dir string) error { if err != nil { return err } - if path == "." || path == ".." { return nil } - - err = deb.AddFile(path) - if err != nil { - return err - } - - return nil + return deb.AddFile(path) }) } diff --git a/debpkg_test.go b/debpkg_test.go index 4fd14c6..7cfcfa9 100644 --- a/debpkg_test.go +++ b/debpkg_test.go @@ -181,6 +181,9 @@ func TestReadWithNativeDpkg(t *testing.T) { } debs, err := filepath.Glob("*.deb") + if err != nil { + t.Errorf("Unexpected error on glob: %v", err) + } for _, deb := range debs { err = dpkg(dpkgCmd, "info", deb) if err != nil { From 367998e1382e2f2cb242255e639f320604cbf0f5 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:42:13 +0200 Subject: [PATCH 09/11] Simplify some calls and handle some errors --- ar.go | 4 +++- data.go | 5 ++++- debpkg.go | 2 +- debpkg_test.go | 6 +----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ar.go b/ar.go index 6acbb60..8dcda5b 100644 --- a/ar.go +++ b/ar.go @@ -43,7 +43,9 @@ func (deb *DebPkg) createDebAr(filename string) error { } }() - deb.data.tgz.Close() + if err := deb.data.tgz.Close(); err != nil { + return fmt.Errorf("cannot close tgz writer: %v", err) + } now := time.Now() w := ar.NewWriter(fd) diff --git a/data.go b/data.go index 2f7170b..6cfb073 100644 --- a/data.go +++ b/data.go @@ -73,7 +73,10 @@ func (d *debPkgData) addFile(filename string, dest ...string) error { return err } - md5, _ := computeMd5(fd) + md5, err := computeMd5(fd) + if err != nil { + return err + } d.size += stat.Size() / 1024 d.md5sums += fmt.Sprintf("%x %s\n", md5, filename) diff --git a/debpkg.go b/debpkg.go index 234cd71..e4c6234 100644 --- a/debpkg.go +++ b/debpkg.go @@ -100,7 +100,7 @@ func (deb *DebPkg) WriteSigned(filename string, entity *openpgp.Entity, keyid st signer = id } - deb.digest.date = fmt.Sprintf(time.Now().Format(time.ANSIC)) + deb.digest.date = time.Now().Format(time.ANSIC) deb.digest.signer = signer clearsign, err := clearsign.Encode(&buf, entity.PrivateKey, &cfg) diff --git a/debpkg_test.go b/debpkg_test.go index 7cfcfa9..a25473c 100644 --- a/debpkg_test.go +++ b/debpkg_test.go @@ -166,11 +166,7 @@ func ExampleWrite() { } func dpkg(cmd, action, filename string) error { - args := []string{"--" + action, filename} - if err := exec.Command(cmd, args...).Run(); err != nil { - return err - } - return nil + return exec.Command(cmd, "--"+action, filename).Run() } func TestReadWithNativeDpkg(t *testing.T) { From 47212833986f66aca2f9649107f8002c24eda608 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:50:30 +0200 Subject: [PATCH 10/11] Recursively traverse directory for AddDirectory --- config_test.go | 2 +- data.go | 3 --- debpkg.go | 11 ++++++++++- lib/targzip/targz.go | 2 -- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/config_test.go b/config_test.go index 0f62a9a..04b469c 100644 --- a/config_test.go +++ b/config_test.go @@ -18,7 +18,7 @@ func TestExampleConfig(t *testing.T) { err := deb.Config("debpkg.yml") if err != nil { - t.Errorf("Unable to open debpkg.yml in CWD: %v", err) + t.Errorf("debpkg.yml error: %v", err) } assert.Equal(t, "7.6.5", deb.control.info.version.full, "Unexpected deb.control.info.version.full") diff --git a/data.go b/data.go index 6cfb073..ea7a653 100644 --- a/data.go +++ b/data.go @@ -29,13 +29,10 @@ func (d *debPkgData) addDirectory(dirpath string) error { return nil } } - if err := d.tgz.AddDirectory(dirpath); err != nil { return err } - d.dirs = append(d.dirs, dirpath) - return nil } diff --git a/debpkg.go b/debpkg.go index e4c6234..7a65e49 100644 --- a/debpkg.go +++ b/debpkg.go @@ -140,13 +140,22 @@ func (deb *DebPkg) AddEmptyDirectory(dir string) error { // AddDirectory adds a directory to the package func (deb *DebPkg) AddDirectory(dir string) error { + deb.data.addDirectory(dir) + return filepath.Walk(dir, func(path string, f os.FileInfo, err error) error { if err != nil { return err } - if path == "." || path == ".." { + if path == "." || path == ".." || dir == path { return nil } + if f.IsDir() { + if err := deb.data.addDirectory(path); err != nil { + return err + } + return deb.AddDirectory(path) + } + return deb.AddFile(path) }) } diff --git a/lib/targzip/targz.go b/lib/targzip/targz.go index c1c7707..9f00a15 100644 --- a/lib/targzip/targz.go +++ b/lib/targzip/targz.go @@ -114,11 +114,9 @@ func (t *TarGzip) AddDirectory(dirpath string) error { ModTime: time.Now(), Size: 0, } - if err := t.WriteHeader(hdr); err != nil { return fmt.Errorf("tar-header for dir: %v", err) } - return nil } From 478aec789823d9e916cc0fdf80282ae11401bd61 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Sun, 28 May 2017 20:55:22 +0200 Subject: [PATCH 11/11] Remove 2017 from copyright, only 2016 is fine --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 2926711..85ef505 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2017 Debpkg authors +Copyright (c) 2016 Debpkg authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal