Skip to content

Commit 5028689

Browse files
committed
cleanup
1 parent a506826 commit 5028689

File tree

3 files changed

+8
-100
lines changed

3 files changed

+8
-100
lines changed

pkg/git.go

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -734,99 +734,6 @@ func registerInGlobalCacheIndex(filePath, url string) {
734734
}
735735
}
736736

737-
// getGlobalRemoteCaches has been removed as it duplicated the cache.GetGlobalRemoteCaches function.
738-
739-
// populateRemoteS3Caches uploads a file to all configured S3 remote caches
740-
func populateRemoteS3Caches(remoteCaches []string, filePath, cacheKey string) {
741-
// Get file stats for verification
742-
fileInfo, err := os.Stat(filePath)
743-
if err != nil {
744-
if !GitQuiet {
745-
color.Yellow("WARNING: Failed to get file info for S3 upload: %v", err)
746-
}
747-
return
748-
}
749-
750-
// Skip directories
751-
if fileInfo.IsDir() {
752-
if !GitQuiet {
753-
color.Yellow("WARNING: Cannot upload directory to S3 cache: %s", filePath)
754-
}
755-
return
756-
}
757-
758-
// Format the S3 key
759-
s3Key := cacheKey + ".tar.gz"
760-
761-
// Loop through remote caches
762-
for _, remoteURL := range remoteCaches {
763-
// Skip non-S3 remotes
764-
if !strings.HasPrefix(remoteURL, "s3://") {
765-
continue
766-
}
767-
768-
if !GitQuiet {
769-
color.Green("Uploading to S3 remote cache: %s/%s", remoteURL, s3Key)
770-
}
771-
772-
// Extract bucket from S3 URL
773-
parsedURL, parseErr := url.Parse(remoteURL)
774-
if parseErr != nil {
775-
if !GitQuiet {
776-
color.Yellow("WARNING: Failed to parse S3 URL %s: %v", remoteURL, parseErr)
777-
}
778-
continue
779-
}
780-
781-
// Get bucket name from URL host
782-
bucket := parsedURL.Host
783-
784-
// Create S3 client using environment variables
785-
client, err := s3.NewClientFromEnv(bucket)
786-
if err != nil {
787-
if !GitQuiet {
788-
color.Yellow("WARNING: Failed to create S3 client for %s: %v", remoteURL, err)
789-
color.Yellow("S3 URL details - Bucket: %s, Query params: %s",
790-
bucket, parsedURL.RawQuery)
791-
}
792-
continue
793-
}
794-
795-
// Check if bucket exists and is accessible before attempting upload
796-
ctx := context.Background()
797-
exists, err := client.BucketExists(ctx)
798-
if err != nil {
799-
if !GitQuiet {
800-
color.Yellow("WARNING: Failed to check if bucket exists: %v", err)
801-
}
802-
continue
803-
}
804-
805-
if !exists {
806-
if !GitQuiet {
807-
color.Yellow("WARNING: Bucket '%s' does not exist or is not accessible", client.Bucket)
808-
}
809-
continue
810-
}
811-
812-
// Upload the file
813-
err = client.Upload(ctx, filePath, s3Key)
814-
if err != nil {
815-
if !GitQuiet {
816-
color.Yellow("WARNING: Failed to upload to S3 cache %s: %v", remoteURL, err)
817-
818-
// Add AWS SDK version for debugging
819-
color.Yellow("Using AWS SDK v2 - Check if credentials and endpoint are correctly configured")
820-
}
821-
continue
822-
}
823-
824-
if !GitQuiet {
825-
color.Green("Successfully populated S3 remote cache: %s", remoteURL)
826-
}
827-
}
828-
}
829-
830737
func gzipUntar(dst string, r io.Reader, subDir string) error {
831738
gzr, err := gzip.NewReader(r)
832739
if err != nil {
@@ -927,7 +834,7 @@ func remoteResolveRef(ctx context.Context, remote string, ref string) (string, e
927834
if err != nil {
928835
return "", err
929836
}
930-
commitShaPattern := regexp.MustCompile("^([0-9a-f]{40,})\\b")
837+
commitShaPattern := regexp.MustCompile(`^([0-9a-f]{40,})\b`)
931838
commitSha := commitShaPattern.FindString(b.String())
932839
return commitSha, nil
933840
}

pkg/local_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package pkg
1616

1717
import (
1818
"context"
19-
"io/ioutil"
2019
"os"
2120
"path/filepath"
2221
"testing"
@@ -30,11 +29,11 @@ func TestLocalInstall(t *testing.T) {
3029
cwd, err := os.Getwd()
3130
assert.NoError(t, err)
3231

33-
vendorDir, err := ioutil.TempDir(cwd, "vendor")
32+
vendorDir, err := os.MkdirTemp(cwd, "vendor")
3433
assert.NoError(t, err)
3534
defer os.RemoveAll(vendorDir)
3635

37-
pkgDir, err := ioutil.TempDir(cwd, "foo")
36+
pkgDir, err := os.MkdirTemp(cwd, "foo")
3837
assert.NoError(t, err)
3938
defer os.RemoveAll(pkgDir)
4039

@@ -51,7 +50,7 @@ func TestLocalInstallSourceNotFound(t *testing.T) {
5150
cwd, err := os.Getwd()
5251
assert.NoError(t, err)
5352

54-
vendorDir, err := ioutil.TempDir(cwd, "vendor")
53+
vendorDir, err := os.MkdirTemp(cwd, "vendor")
5554
assert.NoError(t, err)
5655
defer os.RemoveAll(vendorDir)
5756

@@ -66,7 +65,7 @@ func TestLocalInstallTargetDoesNotExist(t *testing.T) {
6665
cwd, err := os.Getwd()
6766
assert.NoError(t, err)
6867

69-
pkgDir, err := ioutil.TempDir(cwd, "foo")
68+
pkgDir, err := os.MkdirTemp(cwd, "foo")
7069
assert.NoError(t, err)
7170
defer os.RemoveAll(pkgDir)
7271

pkg/packages.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func Ensure(direct v1.JsonnetFile, vendorDir string, oldLocks *deps.Ordered) (*d
8080
names = append(names, path)
8181
return nil
8282
})
83+
if err != nil {
84+
return nil, err
85+
}
8386

8487
// remove them
8588
for _, dir := range names {
@@ -212,7 +215,6 @@ func checkLegacyNameTaken(legacyName string, pkgName string) (bool, error) {
212215
func known(deps *deps.Ordered, p string) bool {
213216
p = filepath.ToSlash(p)
214217

215-
216218
for _, kd := range deps.Keys() {
217219
d, _ := deps.Get(kd)
218220
k := filepath.ToSlash(d.Name())

0 commit comments

Comments
 (0)