Skip to content
Merged
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Jerry Jacobs (@xor-gate)
Rik van der Heijden (@rikvdh)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Jerry Jacobs
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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions ar.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -42,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)
Expand Down
35 changes: 26 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -7,6 +7,7 @@ package debpkg
import (
"fmt"
"io/ioutil"
"runtime"

yaml "gopkg.in/yaml.v2"
)
Expand All @@ -18,6 +19,9 @@ type debPkgSpecFileCfg struct {
Maintainer string `yaml:"maintainer"`
MaintainerEmail string `yaml:"maintainer_email"`
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"`
Expand All @@ -32,18 +36,30 @@ 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),
BuiltUsing: runtime.Version(),
}
cfg.Description.Long = "-"
cfg.Description.Short = "-"

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))
deb.SetName(cfg.Name)
deb.SetVersion(cfg.Version)
deb.SetArchitecture(cfg.Architecture)
Expand All @@ -52,25 +68,26 @@ 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)
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)
}
}

Expand Down
80 changes: 80 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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
Copy link
Owner

Choose a reason for hiding this comment

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

add copyright header


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) {
deb := New()

err := deb.Config("debpkg.yml")
if err != nil {
t.Errorf("debpkg.yml error: %v", err)
}
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)
}
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")
}

func TestNonExistingConfig(t *testing.T) {
deb := New()

err := deb.Config("/non/existant/config/file")
assert.Error(t, err, "error expected")
}
4 changes: 4 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 7 additions & 6 deletions control.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion control_test.go
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
17 changes: 9 additions & 8 deletions data.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -28,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
}

Expand Down Expand Up @@ -72,7 +70,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)

Expand Down
Loading