MCPcopy
hub / github.com/Jguer/yay / srcinfoExists

Function srcinfoExists

local_install.go:27–57  ·  view source on GitHub ↗
(ctx context.Context,
	cmdBuilder exe.ICmdBuilder, targetDir string,
)

Source from the content-addressed store, hash-verified

25var ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory"))
26
27func srcinfoExists(ctx context.Context,
28 cmdBuilder exe.ICmdBuilder, targetDir string,
29) error {
30 srcInfoDir := filepath.Join(targetDir, ".SRCINFO")
31 pkgbuildDir := filepath.Join(targetDir, "PKGBUILD")
32 if _, err := os.Stat(srcInfoDir); err == nil {
33 if _, err := os.Stat(pkgbuildDir); err == nil {
34 return nil
35 }
36 }
37
38 if _, err := os.Stat(pkgbuildDir); err == nil {
39 // run makepkg to generate .SRCINFO
40 srcinfo, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildMakepkgCmd(ctx, targetDir, "--printsrcinfo"))
41 if err != nil {
42 return fmt.Errorf("unable to generate .SRCINFO: %w - %s", err, stderr)
43 }
44
45 if srcinfo == "" {
46 return fmt.Errorf("generated .SRCINFO is empty, check your PKGBUILD for errors")
47 }
48
49 if err := os.WriteFile(srcInfoDir, []byte(srcinfo), 0o600); err != nil {
50 return fmt.Errorf("unable to write .SRCINFO: %w", err)
51 }
52
53 return nil
54 }
55
56 return fmt.Errorf("%w: %s", ErrNoBuildFiles, targetDir)
57}
58
59func installLocalPKGBUILD(
60 ctx context.Context,

Callers 1

installLocalPKGBUILDFunction · 0.85

Calls 2

CaptureMethod · 0.65
BuildMakepkgCmdMethod · 0.65

Tested by

no test coverage detected