Skip to content

Commit

Permalink
Improved templates update
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreavn committed Dec 27, 2024
1 parent e910bea commit 038fc67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Verdex work files
.cache
templates/.cache
targets.txt
output.json

Expand Down
13 changes: 9 additions & 4 deletions verdex/templates/update_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func unpackReleaseWithCallback(destDir string, data *bytes.Reader) error {
callbackFunc := func(uri string, f fs.FileInfo, r io.Reader) error {
uriParts := strings.Split(uri, "/")

// example: verdexlab-verdex-a0b1c2d3/products/keycloak/rules/26.0.5.yml
// example: verdexlab-verdex-a0b1c2d3/templates/keycloak/rules/26.0.5.yml
if len(uriParts) < 2 || uriParts[1] != downloadDirectory || f.IsDir() {
return nil
}
Expand All @@ -109,15 +109,20 @@ func unpackReleaseWithCallback(destDir string, data *bytes.Reader) error {
return nil
}

writeFile := strings.Join(uriParts[2:], "-")
writePath := path.Join(destDir, writeFile)
writeDirectory := path.Join(destDir, strings.Join(uriParts[2:len(uriParts)-1], "/"))
writeFilePath := path.Join(writeDirectory, uriParts[len(uriParts)-1])

bin, err := io.ReadAll(r)
if err != nil {
return fmt.Errorf("failed to read release file %s", uri)
}

return os.WriteFile(writePath, bin, f.Mode())
err = os.MkdirAll(writeDirectory, os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create directory recursively %s", uri)
}

return os.WriteFile(writeFilePath, bin, f.Mode())
}

zipReader, err := zip.NewReader(data, data.Size())
Expand Down

0 comments on commit 038fc67

Please sign in to comment.