-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrrf.go
More file actions
44 lines (40 loc) · 1.08 KB
/
rrf.go
File metadata and controls
44 lines (40 loc) · 1.08 KB
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
package main
import (
"embed"
"fmt"
"io/fs"
"os"
"path/filepath"
)
//go:embed make/libs/.lib/**
var libs embed.FS
func extractFsys(fsys embed.FS, fsroot string, destDir string) error {
return fs.WalkDir(fsys, fsroot, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(fsroot, path)
if err != nil {
return err
}
destPath := filepath.Join(destDir, relPath)
if d.IsDir() {
return os.MkdirAll(destPath, 0o700)
}
data, err := fs.ReadFile(fsys, path)
if err != nil {
return err
}
return os.WriteFile(destPath, data, 0o644)
})
}
func rrfMain() {
if err := os.Mkdir(".lib", 0o700); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to create the directory `%s` in the current directory. The directory may already exist or you may not have write permissions. Please remove or rename the existing directory.\n", ".lib")
os.Exit(cExitCantCreate)
}
if err := extractFsys(libs, "make/libs/.lib", ".lib"); err != nil {
_, _ = fmt.Fprint(os.Stderr, "Failed to extract files.\n")
os.Exit(cExitOsErr)
}
}