Skip to content

Commit

Permalink
normalize ISO files extensions to three chars
Browse files Browse the repository at this point in the history
  • Loading branch information
andfasano committed Jan 11, 2024
1 parent 611e16a commit 6748cdd
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions pkg/asset/agent/image/agentimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"regexp"
Expand All @@ -17,7 +18,8 @@ import (
)

const (
agentISOFilename = "agent.%s.iso"
agentISOFilename = "agent.%s.iso"
iso9660Level1ExtLen = 3
)

// AgentImage is an asset that generates the bootable image used to install clusters.
Expand Down Expand Up @@ -174,6 +176,34 @@ func (a *AgentImage) appendKargs(kargs []byte) error {
return nil
}

// normalizeFilesExtension scans the extracted ISO files and trims
// the file extensions longer than three chars.
func (a *AgentImage) normalizeFilesExtension() error {
return filepath.WalkDir(a.tmpPath, func(p string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
return nil
}

ext := filepath.Ext(p)
// ext includes also the dot separator
if len(ext) > iso9660Level1ExtLen+1 {
// Replaces file extensions longer than three chars
np := p[:len(p)-len(ext)] + ext[:iso9660Level1ExtLen+1]
err = os.Rename(p, np)

if err != nil {
return err
}
}

return nil
})
}

// PersistToFile writes the iso image in the assets folder
func (a *AgentImage) PersistToFile(directory string) error {
defer os.RemoveAll(a.tmpPath)
Expand All @@ -189,7 +219,11 @@ func (a *AgentImage) PersistToFile(directory string) error {
// Remove symlink if it exists
os.Remove(agentIsoFile)

var err error
err := a.normalizeFilesExtension()
if err != nil {
return err
}

// For external platform when the bootArtifactsBaseURL is specified,
// output the rootfs file alongside the minimal ISO
if a.platform == hiveext.ExternalPlatformType {
Expand Down

0 comments on commit 6748cdd

Please sign in to comment.