fix: read multiple depends key from DATA file

This commit is contained in:
ngn 2024-08-26 02:33:38 +03:00
parent 9c61c49b96
commit 6810f9b2ec
2 changed files with 39 additions and 11 deletions

View File

@ -3,13 +3,13 @@ package lib
import (
"archive/tar"
"bufio"
"bytes"
"compress/gzip"
"fmt"
"io"
"net/url"
"os"
"path"
"strings"
"git.matterlinux.xyz/matter/tracker/log"
"github.com/bigkevmcd/go-configparser"
@ -87,12 +87,20 @@ func (p *Package) Load(r io.Reader) error {
var (
err error
size int64
depends string = ""
section string = "DEFAULT"
buffer []byte
)
if buffer, err = io.ReadAll(r); err != nil {
return err
}
if p.Depends, err = GetMultiple("depends", bytes.NewReader(buffer)); err != nil {
return err
}
parser := configparser.New()
if err = parser.ParseReader(r); err != nil {
if err = parser.ParseReader(bytes.NewReader(buffer)); err != nil {
return err
}
@ -123,13 +131,5 @@ func (p *Package) Load(r io.Reader) error {
return err
}
depends, _ = parser.Get(section, "depends")
if depends == "" {
p.Depends = []string{}
} else {
p.Depends = strings.Split(depends, ",")
}
return nil
}

View File

@ -2,6 +2,7 @@ package lib
import (
"archive/tar"
"bufio"
"compress/gzip"
"fmt"
"io"
@ -11,6 +12,33 @@ import (
"github.com/gofiber/fiber/v2"
)
// configparser can't get multiple keys, so heres a function to manually extract them
func GetMultiple(k string, r io.Reader) ([]string, error) {
var (
res []string
value string
scanner *bufio.Scanner
)
scanner = bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Text()
value = strings.TrimPrefix(line, fmt.Sprintf("%s = ", k))
value = strings.TrimPrefix(value, fmt.Sprintf("%s =", k))
value = strings.TrimPrefix(value, fmt.Sprintf("%s= ", k))
value = strings.TrimPrefix(value, fmt.Sprintf("%s=", k))
if line == value {
continue
}
res = append(res, value)
}
return res, nil
}
func GetFiles(r io.Reader) ([]string, error) {
var (
gzip_reader io.Reader