create db links if not exist for all configured repos

This commit is contained in:
2026-05-08 11:46:25 -06:00
parent 7d2324ca56
commit 5aca006249
2 changed files with 50 additions and 0 deletions
+23
View File
@@ -6,6 +6,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"
@@ -59,6 +60,10 @@ func NewCache(cacheRoot string, mirrorURLs []string, mirroredRepos []string) (*C
return nil, err
}
if err := checkSymLinks(cr, mirroredRepos); err != nil {
return nil, err
}
return &Cache{
cfg: cfg,
cr: cr,
@@ -80,3 +85,21 @@ type UpstreamError struct {
func (e *UpstreamError) Error() string {
return fmt.Sprintf("upstream returned %d", e.StatusCode)
}
func checkSymLinks(cr *os.Root, repos []string) error {
for _, repo := range repos {
dirPath := filepath.Join(repo, "os/x86_64")
if err := cr.MkdirAll(dirPath, 0750); err != nil {
return err
}
lnPath := filepath.Join(dirPath, repo+".db")
srcPath := filepath.Join(dirPath, repo+".db.tar.gz")
if _, err := cr.Lstat(lnPath); err == nil {
continue // link exists
}
if err := cr.Symlink(srcPath, lnPath); err != nil {
return err
}
}
return nil
}