Skip to content

Commit

Permalink
fix(initrd): Several small fixes (#957)
Browse files Browse the repository at this point in the history
Approved-by: Antoine Cotten <antoine@unikraft.io>
  • Loading branch information
antoineco committed Nov 2, 2023
2 parents 4941002 + c40f9a1 commit f05b84f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion initrd/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type directory struct {
// NewFromDirectory returns an instantiated Initrd interface which is is able to
// serialize a rootfs from a given directory.
func NewFromDirectory(_ context.Context, path string, opts ...InitrdOption) (Initrd, error) {
path = strings.TrimRight(path, string(filepath.Separator))
rootfs := directory{
opts: InitrdOptions{},
path: path,
Expand Down Expand Up @@ -54,10 +55,14 @@ func (initrd *directory) Build(ctx context.Context) (string, error) {
if initrd.opts.output == "" {
fi, err := os.CreateTemp("", "")
if err != nil {
return "", fmt.Errorf("could not make temporary directory: %w", err)
return "", fmt.Errorf("could not make temporary file: %w", err)
}

initrd.opts.output = fi.Name()
err = fi.Close()
if err != nil {
return "", fmt.Errorf("could not close temporary file: %w", err)
}
}

f, err := os.OpenFile(initrd.opts.output, os.O_RDWR|os.O_CREATE, 0o644)
Expand All @@ -76,6 +81,7 @@ func (initrd *directory) Build(ctx context.Context) (string, error) {
}

internal := strings.TrimPrefix(path, filepath.Clean(initrd.path))
internal = filepath.ToSlash(internal)
if internal == "" {
return nil // Do not archive empty paths
}
Expand Down

0 comments on commit f05b84f

Please sign in to comment.