Skip to content

Commit

Permalink
initramfs: follow symlinks on host file system.
Browse files Browse the repository at this point in the history
Should also fix u-root#842.
  • Loading branch information
hugelgupf committed Oct 17, 2018
1 parent acfc08b commit 69d8a7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pkg/cpio/fs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ func inode(i Info) (Info, bool) {
return i, false
}

func GetFollowedRecord(path string) (Record, error) {
fi, err := os.Stat(path)
if err != nil {
return Record{}, err
}

sys := fi.Sys().(*syscall.Stat_t)
info, done := inode(sysInfo(path, sys))

switch fi.Mode() & os.ModeType {
case 0: // Regular file.
if done {
return Record{Info: info}, nil
}
return Record{Info: info, ReaderAt: NewLazyFile(path)}, nil

default:
return StaticRecord(nil, info), nil
}
}

func GetRecord(path string) (Record, error) {
fi, err := os.Lstat(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/uroot/initramfs/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (af *Files) WriteTo(w Writer) error {
//
// If `src` is a directory, its children will be added to the archive as well.
func writeFile(w Writer, src, dest string) error {
record, err := cpio.GetRecord(src)
record, err := cpio.GetFollowedRecord(src)
if err != nil {
return err
}
Expand Down

0 comments on commit 69d8a7a

Please sign in to comment.