moved build_map to db file as it contains matching functions and db logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package repomaint
|
package repomaint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ewpt3ch/pkgstash/internal/cache"
|
"github.com/ewpt3ch/pkgstash/internal/cache"
|
||||||
@@ -37,13 +38,20 @@ func NewRepoSync(c CacheClient, path string, repos []string) (*RepoSync, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RepoSync) Sync() error {
|
func (r *RepoSync) Sync() error {
|
||||||
|
|
||||||
|
for _, repo := range r.repos {
|
||||||
// create map of pkgname to filenames from current db
|
// create map of pkgname to filenames from current db
|
||||||
|
cachedPkgs, err := r.buildMap(repo)
|
||||||
|
slog.Warn("failed to read current db", "err", err)
|
||||||
|
|
||||||
// call cache db fetch
|
// call cache db fetch
|
||||||
if err := r.c.FetchDB(); err != nil {
|
if err := r.c.FetchDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// create map from pkgnames in new db
|
|
||||||
|
}
|
||||||
// compare and fetch
|
// compare and fetch
|
||||||
|
|
||||||
// call cache cleanup
|
// call cache cleanup
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,10 @@ func TestCachedFiles(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create RepoMaint: %v", err)
|
t.Fatalf("failed to create RepoMaint: %v", err)
|
||||||
}
|
}
|
||||||
rs.root.MkdirAll("core/os/x86_64", 0750)
|
repoPath := filepath.Join("core", repoArch)
|
||||||
|
rs.root.MkdirAll(repoPath, 0750)
|
||||||
for _, f := range testFiles {
|
for _, f := range testFiles {
|
||||||
rs.root.WriteFile(filepath.Join("core/os/x86_64", f), []byte{}, 0644)
|
rs.root.WriteFile(filepath.Join(repoPath, f), []byte{}, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedFiles, err := rs.cachedPkgs("core")
|
cachedFiles, err := rs.cachedPkgs("core")
|
||||||
@@ -81,7 +82,7 @@ func TestSyncMapBuild(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create RepoMaint: %v", err)
|
t.Fatalf("failed to create RepoMaint: %v", err)
|
||||||
}
|
}
|
||||||
repoPath := filepath.Join(rs.repos[0], "os/x86_64")
|
repoPath := filepath.Join(rs.repos[0], repoArch)
|
||||||
rs.root.MkdirAll(repoPath, 0750)
|
rs.root.MkdirAll(repoPath, 0750)
|
||||||
for _, f := range testFiles {
|
for _, f := range testFiles {
|
||||||
rs.root.WriteFile(filepath.Join(repoPath, f), []byte{}, 0644)
|
rs.root.WriteFile(filepath.Join(repoPath, f), []byte{}, 0644)
|
||||||
@@ -102,7 +103,7 @@ func TestSyncMapBuild(t *testing.T) {
|
|||||||
|
|
||||||
// run tests
|
// run tests
|
||||||
|
|
||||||
pkgMap, err := rs.createMap(rs.repos[0])
|
pkgMap, err := rs.buildMap(rs.repos[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create map: %v", err)
|
t.Fatalf("failed to create map: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user