commit ba61651
chld
·
2026-02-07 23:33:08 +0000 UTC
parent 1593a4c
functionize manifest generation
2 files changed,
+59,
-50
+1,
-50
1@@ -35,11 +35,6 @@ func Inst(pkg string) {
2 }
3 }
4
5- /*
6- if err != nil {
7- dgr.Die("failed to copy package files to root", os.Getenv("DTR_ROOT"), 1)
8- } else {
9- */
10 // write the installed package to a installed file for tracking
11 fx, _ := os.ReadFile(filepath.Join(os.Getenv("DTR_DB"), "installed"))
12 fxx := strings.Fields(string(fx))
13@@ -50,51 +45,7 @@ func Inst(pkg string) {
14 }
15 }
16
17- f, err := os.OpenFile(
18- filepath.Join(os.Getenv("DTR_DB"), "installed"),
19- os.O_WRONLY|os.O_APPEND, 0644) // make sure to append, r/w access
20- if err != nil {
21- dgr.Die("could not open file", filepath.Join(os.Getenv("DTR_DB"), "installed"), 1)
22- }
23- defer f.Close()
24- f.Write([]byte(pkg))
25- f.Write([]byte{10}) // write a EOL too!
26- f.Sync()
27-
28- // create a manifest file
29- dgr.Msg("creating manifest file for \033[33m", pkg, "\033[m")
30-
31- os.MkdirAll(filepath.Join(os.Getenv("DTR_DB"), pkg), 0755)
32- pkgm := filepath.Join(os.Getenv("DTR_DB"), pkg, "manifest")
33-
34- m, err := os.Create(pkgm)
35- if err != nil {
36- dgr.Die("could not create manifest file", pkgm, 1)
37- }
38- defer m.Close()
39-
40- pkr, _ := filepath.Glob(pkginst)
41- if err := os.Chdir(strings.Join(pkr, "")); err != nil {
42- dgr.Die("could not chdir to path", strings.Join(pkr, ""), 1)
43- }
44-
45- err = filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
46- if err != nil {
47- return err
48- }
49-
50- // skip the root "."
51- if path == "." {
52- return nil
53- }
54-
55- fmt.Fprintln(m, "/"+path) // write paths to m
56- return nil
57- })
58-
59- if err != nil {
60- panic(err)
61- }
62+ GenM(pkg, pkginst) // generate manifest
63
64 dgr.Msg("installed \033[1;32m", pkg, "\033[m successfully")
65 //}
+58,
-0
1@@ -0,0 +1,58 @@
2+package dgrb
3+
4+import (
5+ "fmt"
6+ "git.sr.ht/~chld/dgr/cmd"
7+ "os"
8+ "path/filepath"
9+ "strings"
10+)
11+
12+func GenM(pkg string, pkginst string) {
13+ f, err := os.OpenFile(
14+ filepath.Join(os.Getenv("DTR_DB"), "installed"),
15+ os.O_WRONLY|os.O_APPEND, 0644) // make sure to append, r/w access
16+ if err != nil {
17+ dgr.Die("could not open file", filepath.Join(os.Getenv("DTR_DB"), "installed"), 1)
18+ }
19+ defer f.Close()
20+ f.Write([]byte(pkg))
21+ f.Write([]byte{10}) // write a EOL too!
22+ f.Sync()
23+
24+ // create a manifest file
25+ dgr.Msg("creating manifest file for \033[33m", pkg, "\033[m")
26+
27+ os.MkdirAll(filepath.Join(os.Getenv("DTR_DB"), pkg), 0755)
28+ pkgm := filepath.Join(os.Getenv("DTR_DB"), pkg, "manifest")
29+
30+ m, err := os.Create(pkgm)
31+ if err != nil {
32+ dgr.Die("could not create manifest file", pkgm, 1)
33+ }
34+ defer m.Close()
35+
36+ pkr, _ := filepath.Glob(pkginst)
37+ if err := os.Chdir(strings.Join(pkr, "")); err != nil {
38+ dgr.Die("could not chdir to path", strings.Join(pkr, ""), 1)
39+ }
40+
41+ err = filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
42+ if err != nil {
43+ return err
44+ }
45+
46+ // skip the root "."
47+ if path == "." {
48+ return nil
49+ }
50+
51+ fmt.Fprintln(m, "/"+path) // write paths to m
52+ return nil
53+ })
54+
55+ if err != nil {
56+ panic(err)
57+ }
58+
59+}