1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00

dont add folders to archive

This commit is contained in:
Carlos Alexandro Becker 2017-05-11 09:36:04 -03:00
parent 0ae005b42f
commit 5eac3fd7b1
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 11 additions and 1 deletions

View File

@ -46,7 +46,7 @@ func (a Archive) Add(name, path string) (err error) {
_ = file.Close()
}()
stat, err := file.Stat()
if err != nil {
if err != nil || stat.IsDir() {
return
}
header := new(tar.Header)

View File

@ -23,9 +23,12 @@ func TestTarGzFile(t *testing.T) {
empty2, err := os.Create(folder + "/empty2.txt")
assert.NoError(err)
assert.NoError(os.Mkdir(folder+"/folder-inside", 0755))
archive := New(file)
assert.NoError(archive.Add("empty.txt", empty.Name()))
assert.Error(archive.Add("dont.txt", empty.Name()+"_nope"))
assert.NoError(archive.Add("empty.txt", folder+"/folder-inside"))
assert.NoError(archive.Close())
assert.Error(archive.Add("empty2.txt", empty2.Name()))
}

View File

@ -31,6 +31,10 @@ func (a Archive) Add(name, path string) (err error) {
if err != nil {
return
}
stat, err := file.Stat()
if err != nil || stat.IsDir() {
return
}
defer func() { _ = file.Close() }()
f, err := a.z.Create(name)
if err != nil {

View File

@ -20,8 +20,11 @@ func TestZipFile(t *testing.T) {
empty, err := os.Create(folder + "/empty.txt")
assert.NoError(err)
assert.NoError(os.Mkdir(folder+"/folder-inside", 0755))
archive := New(file)
assert.NoError(archive.Add("empty.txt", empty.Name()))
assert.NoError(archive.Add("empty.txt", folder+"/folder-inside"))
assert.Error(archive.Add("dont.txt", empty.Name()+"_nope"))
assert.NoError(archive.Close())
}