-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2023 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// list all files in / and create a cpio from them.
package main
import (
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"github.com/u-root/u-root/pkg/cpio"
)
func main() {
archiver, err := cpio.Format("newc")
if err != nil {
log.Fatal(err)
}
rw := archiver.Writer(os.Stdout)
cr := cpio.NewRecorder()
if err := filepath.WalkDir("/", func(n string, d fs.DirEntry, err error) error {
// Even for directories we skip, add a record.
rec, err := cr.GetRecord(n)
if err != nil {
return fmt.Errorf("Getting record of %q (%v) failed: %w", n, d, err)
}
if err := rw.WriteRecord(rec); err != nil {
return fmt.Errorf("Writing record %q (%v) failed: %w", n, d, err)
}
log.Printf("%q", n)
switch n {
case "/home", "/sys", "/dev", "/proc", "/root":
return fs.SkipDir
}
return nil
}); err != nil {
log.Fatal(err)
}
if err := cpio.WriteTrailer(rw); err != nil {
log.Fatalf("Error writing trailer record: %w", err)
}
}