create db links if not exist for all configured repos
This commit is contained in:
Vendored
+23
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user