Always compress if content isn't a valid utf8 string
package bundle
import (
- "bytes"
"context"
"io/ioutil"
"net/url"
@@ -10,6 +9,7 @@ import (
"sort"
"strings"
"sync"
+ "unicode/utf8"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
@@ -187,7 +187,7 @@ func readDirectory(ctx context.Context, progress *progress.Progress, compress bo
for i, resource := range resources {
data := files[resource.Name]
- if compress || hasZero(data) {
+ if compress || !utf8.Valid(data) {
content, err := content.Base64GZ(files[resource.Name])
if err != nil {
return nil, err
@@ -209,10 +209,6 @@ func readDirectory(ctx context.Context, progress *progress.Progress, compress bo
return resources, nil
}
-func hasZero(data []byte) bool {
- return bytes.ContainsRune(data, 0x0)
-}
-
func readContent(ctx context.Context, progress *progress.Progress, base, name string) (map[string][]byte, error) {
temp, err := ioutil.TempDir("", "fleet")
if err != nil {
@@ -254,6 +250,9 @@ func readContent(ctx context.Context, progress *progress.Progress, base, name st
err = filepath.Walk(temp, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
+ if strings.HasPrefix(filepath.Base(path), ".") {
+ return filepath.SkipDir
+ }
return nil
}
@@ -262,6 +261,10 @@ func readContent(ctx context.Context, progress *progress.Progress, base, name st
return err
}
+ if strings.HasPrefix(filepath.Base(name), ".") {
+ return nil
+ }
+
content, err := ioutil.ReadFile(path)
if err != nil {
return err
