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
…#1963)

Reviewed-by: Cezar Craciunoiu <[email protected]>
Approved-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc authored Nov 19, 2024
2 parents 984d042 + cd33bf1 commit 442234b
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 442234b

Please sign in to comment.