commit a036fcf

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