1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-09-25 17:51:11 +02:00

fix: improve mapresponses and profiles extraction in hi tool

- Fix directory hierarchy flattening by using full paths instead of filepath.Base()
- Remove redundant container hostname prefixes from directory names
- Strip top-level directory from tar extraction to avoid nested structure
- Ensure parent directories exist before creating files
- Results in clean structure: control_logs/mapresponses/1-ts-client/file.json
This commit is contained in:
Kristoffer Dalby 2025-08-27 11:53:44 +02:00
parent 8e25f7f9dd
commit 64028e25af
No known key found for this signature in database

View File

@ -641,7 +641,6 @@ func extractTarToDirectory(tarData []byte, targetDir string) error {
} }
} }
// Second pass: extract files, stripping the top-level directory
tarReader = tar.NewReader(bytes.NewReader(tarData)) tarReader = tar.NewReader(bytes.NewReader(tarData))
for { for {
header, err := tarReader.Next() header, err := tarReader.Next()
@ -665,7 +664,6 @@ func extractTarToDirectory(tarData []byte, targetDir string) error {
// Skip the top-level directory itself // Skip the top-level directory itself
continue continue
} }
// Skip empty paths after stripping // Skip empty paths after stripping
if cleanName == "" { if cleanName == "" {
continue continue
@ -684,7 +682,6 @@ func extractTarToDirectory(tarData []byte, targetDir string) error {
if err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil { if err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil {
return fmt.Errorf("failed to create parent directories for %s: %w", targetPath, err) return fmt.Errorf("failed to create parent directories for %s: %w", targetPath, err)
} }
// Create file // Create file
outFile, err := os.Create(targetPath) outFile, err := os.Create(targetPath)
if err != nil { if err != nil {