renamed var
This commit is contained in:
+3
-3
@@ -16,9 +16,9 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
|
|||||||
arch := req.PathValue("arch")
|
arch := req.PathValue("arch")
|
||||||
file := req.PathValue("file")
|
file := req.PathValue("file")
|
||||||
repoPath := filepath.Join(repo, "os", arch, file) //path from mirror root to pkg or db file
|
repoPath := filepath.Join(repo, "os", arch, file) //path from mirror root to pkg or db file
|
||||||
pkgPath := filepath.Join(s.cfg.CacheRoot, repoPath) //absolute path for local read of the file
|
cachePath := filepath.Join(s.cfg.CacheRoot, repoPath) //absolute path for local read of the file
|
||||||
|
|
||||||
if _, err := os.Stat(pkgPath); err != nil {
|
if _, err := os.Stat(cachePath); err != nil {
|
||||||
err = s.c.Fetch(repoPath)
|
err = s.c.Fetch(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var upstreamErr *cache.UpstreamError
|
var upstreamErr *cache.UpstreamError
|
||||||
@@ -31,5 +31,5 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ServeFile(w, req, pkgPath)
|
http.ServeFile(w, req, cachePath)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
-5
@@ -12,16 +12,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
localRoot string
|
cacheRoot string
|
||||||
mirrorURL string
|
mirrorURL string
|
||||||
mirroredRepos []string
|
mirroredRepos []string
|
||||||
sf singleflight.Group //prevents duplicate downloads
|
sf singleflight.Group //prevents duplicate downloads
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCache(localRoot string, mirrorURL string) *Cache {
|
func NewCache(cacheRoot string, mirrorURL string) *Cache {
|
||||||
return &Cache{
|
return &Cache{
|
||||||
localRoot: localRoot,
|
cacheRoot: cacheRoot,
|
||||||
mirrorURL: mirrorURL,
|
mirrorURL: mirrorURL,
|
||||||
mirroredRepos: []string{"core", "extra"},
|
mirroredRepos: []string{"core", "extra"},
|
||||||
}
|
}
|
||||||
@@ -44,9 +44,10 @@ func (e *UpstreamError) Error() string {
|
|||||||
|
|
||||||
func (c *Cache) fetch(pkgName string) error {
|
func (c *Cache) fetch(pkgName string) error {
|
||||||
// pkgName is relative to the localRoot
|
// pkgName is relative to the localRoot
|
||||||
|
// ie pkgName includes /{repo}/os/{arch}/ and the actual name linux-x.x.x.pkg.tar.zst
|
||||||
tempPkgName := pkgName + ".tmp"
|
tempPkgName := pkgName + ".tmp"
|
||||||
tempPkgPath := filepath.Join(c.localRoot, tempPkgName) //full tmp write path
|
tempPkgPath := filepath.Join(c.cacheRoot, tempPkgName) //full tmp write path
|
||||||
outPkg := filepath.Join(c.localRoot, pkgName)
|
outPkg := filepath.Join(c.cacheRoot, pkgName)
|
||||||
pkgURL := c.mirrorURL + pkgName
|
pkgURL := c.mirrorURL + pkgName
|
||||||
|
|
||||||
resp, err := http.Get(pkgURL)
|
resp, err := http.Get(pkgURL)
|
||||||
|
|||||||
Reference in New Issue
Block a user