From 2735749b12c98c598cf702ab6ecb2543483d6cf3 Mon Sep 17 00:00:00 2001 From: roboogg133 Date: Tue, 23 Sep 2025 19:12:08 -0300 Subject: [PATCH] Added a function to read manifest from the file manifest.toml and not only from a package file --- internal/utils/utils.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index ee4bb38..ca852e9 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -8,11 +8,12 @@ import ( "log" "net/http" "os" + "path/filepath" + "strings" + "packets/configs" "packets/internal/consts" errors_packets "packets/internal/errors" - "path/filepath" - "strings" "github.com/klauspost/compress/zstd" "github.com/pelletier/go-toml/v2" @@ -42,7 +43,6 @@ type Package struct { } func GetFileHTTP(url string) ([]byte, error) { - resp, err := http.Get(url) if err != nil { log.Fatal(err) @@ -84,7 +84,7 @@ func ReadManifest(file io.Reader) (configs.Manifest, error) { var manifest configs.Manifest if err := decoder.Decode(&manifest); err != nil { - log.Fatal(err) + return configs.Manifest{}, nil } return manifest, nil @@ -105,7 +105,7 @@ func CopyDir(src string, dest string) error { return err } - if err := os.MkdirAll(dest, 0755); err != nil { + if err := os.MkdirAll(dest, 0o755); err != nil { return err } @@ -137,18 +137,15 @@ func CopyDir(src string, dest string) error { return err } } - } return nil } // CopyFile copies a file from source to destination func CopyFile(source string, destination string) error { - src, err := os.Open(source) if err != nil { return err - } defer src.Close() @@ -157,7 +154,7 @@ func CopyFile(source string, destination string) error { return err } - err = os.MkdirAll(filepath.Dir(destination), 0755) + err = os.MkdirAll(filepath.Dir(destination), 0o755) if err != nil { return err } @@ -189,8 +186,7 @@ func CopyFile(source string, destination string) error { // Write writes the package file to the cache directory and returns the path to it func (p *Package) Write() (string, error) { - - if err := os.WriteFile(filepath.Join(consts.DefaultCache_d, p.Filename), p.PackageF, 0644); err != nil { + if err := os.WriteFile(filepath.Join(consts.DefaultCache_d, p.Filename), p.PackageF, 0o644); err != nil { _ = os.Remove(filepath.Join(consts.DefaultCache_d, p.Filename)) return "", err } @@ -272,3 +268,15 @@ func GetDependencies(name string) ([]string, error) { return strings.Fields(dependenciesRaw), nil } + +func ManifestFileRead(file io.Reader) (configs.Manifest, error) { + decoder := toml.NewDecoder(file) + + var manifest configs.Manifest + + if err := decoder.Decode(&manifest); err != nil { + return configs.Manifest{}, nil + } + + return manifest, nil +}