Skip to content

Commit

Permalink
fix(initrd): Use stat as a more robust mechanic for checking a file
Browse files Browse the repository at this point in the history
This would also pass for other types, especially directories, which
is problematic, as this is also an initrd-provider.

Signed-off-by: Alexander Jung <alex@unikraft.io>
  • Loading branch information
nderjung committed Nov 19, 2024
1 parent e44ef1e commit cd33bf1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions initrd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package initrd

import (
"context"
"fmt"
"os"
)

Expand All @@ -17,11 +18,13 @@ type file struct {
// NewFromFile accepts an input file which already represents a CPIO archive and
// is provided as a mechanism for satisfying the Initrd interface.
func NewFromFile(_ context.Context, path string, opts ...InitrdOption) (Initrd, error) {
fi, err := os.Open(path)
stat, err := os.Stat(path)
if err != nil {
return nil, err
}
defer fi.Close()
if stat.IsDir() {
return nil, fmt.Errorf("path %s is a directory, not a file", path)
}

initrd := file{
opts: InitrdOptions{},
Expand Down

0 comments on commit cd33bf1

Please sign in to comment.