-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
85 lines (71 loc) · 1.99 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
// Creates the fullfiles for a specific version given a state
// directory. Used to test the logic in the library functions.
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime/pprof"
"github.com/clearlinux/mixer-tools/swupd"
)
func usage() {
log.Printf(`Usage: create-fullfiles [FLAGS] STATEDIR VERSION
Flags:
`)
flag.PrintDefaults()
os.Exit(2)
}
func main() {
log.SetFlags(0)
cpuProfile := flag.String("cpuprofile", "", "write CPU profile to a file")
outputDir := flag.String("o", "", "output directory, creates temporary if not specified")
flag.Usage = usage
flag.Parse()
if flag.NArg() != 2 {
usage()
}
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
log.Fatalf("couldn't create file for CPU profile: %s", err)
}
_ = pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
stateDir := flag.Arg(0)
version := flag.Arg(1)
chrootDir := filepath.Join(stateDir, "image", version, "full")
if _, err := os.Stat(chrootDir); err != nil {
log.Fatalf("couldn't access the full chroot: %s", err)
}
manifestFile := filepath.Join(stateDir, "www", version, "Manifest.full")
if _, err := os.Stat(manifestFile); err != nil {
log.Fatalf("couldn't access the full manifest: %s", err)
}
m, err := swupd.ParseManifestFile(manifestFile)
if err != nil {
log.Fatalf("couldn't read full manifest %s: %s", manifestFile, err)
}
if *outputDir == "" {
tempDir, terr := ioutil.TempDir(".", "fullfiles-")
if terr != nil {
log.Fatalf("couldn't create output directory: %s", terr)
}
*outputDir = tempDir
} else {
if _, err = os.Stat(*outputDir); err == nil {
log.Fatalf("output dir already exists, exiting to not overwrite files")
}
err = os.MkdirAll(*outputDir, 0755)
if err != nil {
log.Fatalf("couldn't create output directory: %s", err)
}
}
log.Printf("Output directory: %s", *outputDir)
_, err = swupd.CreateFullfiles(m, chrootDir, *outputDir, 0, []string{"external-xz"})
if err != nil {
log.Fatal(err)
}
}