|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|
|
|
|
package repo // import "helm.sh/helm/v4/pkg/repo"
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"bytes"
|
|
|
|
|
"crypto/rand"
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"encoding/json"
|
|
|
|
@ -28,10 +28,8 @@ import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/gofrs/flock"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/internal/fileutil"
|
|
|
|
|
"helm.sh/helm/v4/pkg/getter"
|
|
|
|
|
"helm.sh/helm/v4/pkg/helmpath"
|
|
|
|
|
)
|
|
|
|
@ -110,42 +108,15 @@ func (r *ChartRepository) DownloadIndexFile() (string, error) {
|
|
|
|
|
for name := range indexFile.Entries {
|
|
|
|
|
fmt.Fprintln(&charts, name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chartsFile := filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name))
|
|
|
|
|
os.MkdirAll(filepath.Dir(chartsFile), 0755)
|
|
|
|
|
|
|
|
|
|
fname := filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name))
|
|
|
|
|
os.MkdirAll(filepath.Dir(fname), 0755)
|
|
|
|
|
|
|
|
|
|
// context for lock files
|
|
|
|
|
lockCtx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
// lock the charts file
|
|
|
|
|
chLock := flock.New(filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name)+".lock"))
|
|
|
|
|
chLocked, err := chLock.TryLockContext(lockCtx, 500*time.Millisecond)
|
|
|
|
|
if err == nil && chLocked {
|
|
|
|
|
defer chLock.Unlock()
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write charts files after lock
|
|
|
|
|
os.WriteFile(chartsFile, []byte(charts.String()), 0644)
|
|
|
|
|
|
|
|
|
|
// lock the index file
|
|
|
|
|
idxLock := flock.New(filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name)+".lock"))
|
|
|
|
|
idxLocked, err := idxLock.TryLockContext(lockCtx, 500*time.Millisecond)
|
|
|
|
|
if err == nil && idxLocked {
|
|
|
|
|
defer idxLock.Unlock()
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
fileutil.AtomicWriteFile(chartsFile, bytes.NewReader([]byte(charts.String())), 0644)
|
|
|
|
|
|
|
|
|
|
// Create the index file in the cache directory
|
|
|
|
|
return fname, os.WriteFile(fname, index, 0644)
|
|
|
|
|
fname := filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name))
|
|
|
|
|
os.MkdirAll(filepath.Dir(fname), 0755)
|
|
|
|
|
return fname, fileutil.AtomicWriteFile(fname, bytes.NewReader(index), 0644)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type findChartInRepoURLOptions struct {
|
|
|
|
|