|
|
@ -18,7 +18,6 @@ package repo
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
@ -31,7 +30,6 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
"github.com/gofrs/flock"
|
|
|
|
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/internal/fileutil"
|
|
|
|
"helm.sh/helm/v4/internal/fileutil"
|
|
|
@ -105,19 +103,6 @@ func NewIndexFile() *IndexFile {
|
|
|
|
|
|
|
|
|
|
|
|
// LoadIndexFile takes a file at the given path and returns an IndexFile object
|
|
|
|
// LoadIndexFile takes a file at the given path and returns an IndexFile object
|
|
|
|
func LoadIndexFile(path string) (*IndexFile, error) {
|
|
|
|
func LoadIndexFile(path string) (*IndexFile, error) {
|
|
|
|
lockCtx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
idxLock := flock.New(filepath.Join(path + ".lock"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
idxLocked, err := idxLock.TryRLockContext(lockCtx, 500*time.Millisecond)
|
|
|
|
|
|
|
|
if err == nil && idxLocked {
|
|
|
|
|
|
|
|
defer idxLock.Unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b, err := os.ReadFile(path)
|
|
|
|
b, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -240,19 +225,6 @@ func (i IndexFile) Get(name, version string) (*ChartVersion, error) {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// The mode on the file is set to 'mode'.
|
|
|
|
// The mode on the file is set to 'mode'.
|
|
|
|
func (i IndexFile) WriteFile(dest string, mode os.FileMode) error {
|
|
|
|
func (i IndexFile) WriteFile(dest string, mode os.FileMode) error {
|
|
|
|
lockCtx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
idxLock := flock.New(dest + ".lock")
|
|
|
|
|
|
|
|
idxLocked, err := idxLock.TryLockContext(lockCtx, 500*time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil && idxLocked {
|
|
|
|
|
|
|
|
defer idxLock.Unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b, err := yaml.Marshal(i)
|
|
|
|
b, err := yaml.Marshal(i)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -265,19 +237,6 @@ func (i IndexFile) WriteFile(dest string, mode os.FileMode) error {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// The mode on the file is set to 'mode'.
|
|
|
|
// The mode on the file is set to 'mode'.
|
|
|
|
func (i IndexFile) WriteJSONFile(dest string, mode os.FileMode) error {
|
|
|
|
func (i IndexFile) WriteJSONFile(dest string, mode os.FileMode) error {
|
|
|
|
lockCtx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
idxLock := flock.New(dest + ".lock")
|
|
|
|
|
|
|
|
idxLocked, err := idxLock.TryLockContext(lockCtx, 500*time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil && idxLocked {
|
|
|
|
|
|
|
|
defer idxLock.Unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(i, "", " ")
|
|
|
|
b, err := json.MarshalIndent(i, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|