Skip to content
Snippets Groups Projects
Commit 77606004 authored by q3k's avatar q3k
Browse files

dist: add directories to tar

parent a873a2e4
Branches
No related tags found
No related merge requests found
...@@ -139,6 +139,8 @@ func (s *server) targzApp(ctx context.Context, name, pathInRepo, repo string, ob ...@@ -139,6 +139,8 @@ func (s *server) targzApp(ctx context.Context, name, pathInRepo, repo string, ob
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
gz := gzip.NewWriter(buf) gz := gzip.NewWriter(buf)
t := tar.NewWriter(gz) t := tar.NewWriter(gz)
directories := make(map[string]bool)
for { for {
f, err := fi.Next() f, err := fi.Next()
if err == io.EOF { if err == io.EOF {
...@@ -160,10 +162,31 @@ func (s *server) targzApp(ctx context.Context, name, pathInRepo, repo string, ob ...@@ -160,10 +162,31 @@ func (s *server) targzApp(ctx context.Context, name, pathInRepo, repo string, ob
p := f.Name[len(prefix):] p := f.Name[len(prefix):]
prefix = strings.ReplaceAll(repo, "/", "-") prefix = strings.ReplaceAll(repo, "/", "-")
outPath := path.Join(prefix, p) outPath := path.Join(prefix, p)
dirs, _ := path.Split(outPath)
if dirs != "" {
parts := strings.Split(dirs, "/")
cur := parts[0]
for i := 1; i < len(parts); i++ {
cur += parts[i]
if !directories[cur] {
directories[cur] = true
err = t.WriteHeader(&tar.Header{
Name: cur,
Typeflag: tar.TypeDir,
Mode: 0755,
})
if err != nil {
return nil, fmt.Errorf("CreateDir(%q): %w", cur, err)
}
}
}
}
err = t.WriteHeader(&tar.Header{ err = t.WriteHeader(&tar.Header{
Name: outPath, Name: outPath,
Typeflag: tar.TypeReg, Typeflag: tar.TypeReg,
Size: f.Size, Size: f.Size,
Mode: 0644,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("Create(%q): %w", outPath, err) return nil, fmt.Errorf("Create(%q): %w", outPath, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment