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:
parent
0ae005b42f
commit
5eac3fd7b1
@ -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)
|
||||
|
@ -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()))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user