Skip to content

Commit 50b783a

Browse files
committed
fix(initrd): Correctly copy rootfs when using files
Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
1 parent 398a6d3 commit 50b783a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

initrd/file.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,21 @@ func (initrd *file) Name() string {
6161

6262
// Build implements Initrd.
6363
func (initrd *file) Build(_ context.Context) (string, error) {
64-
return initrd.path, nil
64+
if initrd.opts.output == initrd.path {
65+
return "", fmt.Errorf("CPIO archive path is the same as the source path, this is not allowed as it creates corrupted archives")
66+
}
67+
68+
input, err := os.ReadFile(initrd.path)
69+
if err != nil {
70+
return "", fmt.Errorf("reading input file: %w", err)
71+
}
72+
73+
err = os.WriteFile(initrd.opts.output, input, 0o644)
74+
if err != nil {
75+
return "", fmt.Errorf("writing output file: %w", err)
76+
}
77+
78+
return initrd.opts.output, nil
6579
}
6680

6781
// Options implements Initrd.

0 commit comments

Comments
 (0)