aboutsummaryrefslogtreecommitdiff
path: root/internal/slackware_com/file_system.go
blob: 18769be45d176b13c36c0a54efdfd9e25ff4e2da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package slackware_com

import (
	"fmt"
	"os"
	"path"
)

const PkgToolsPath = "/var/lib/pkgtools"

const PkgToolsPackagesPath = "packages"

type PackageStore struct {
	filePath string
}

func NewPackageStore(filePath string) (*PackageStore, error) {
	packageStore := PackageStore{
		filePath: filePath,
	}

	return &packageStore, nil
}

func (p *PackageStore) GetInstalledPackages() ([]PackageName, error) {
	var packages []PackageName

	entries, err := os.ReadDir(path.Join(p.filePath, PkgToolsPackagesPath))
	if err != nil {
		return nil, err
	}

	for _, entry := range entries {
		pkg, err := NewPackageName(entry.Name())
		if err != nil {
			return nil, fmt.Errorf("corrupted data: %w", err)
		}
		packages = append(packages, pkg)
	}

	return packages, nil
}