fix wasi-libc caching path

This commit is contained in:
Li Jie
2025-08-16 10:48:16 +08:00
parent b650a546cd
commit 21174e44bb
2 changed files with 29 additions and 35 deletions

View File

@@ -12,36 +12,36 @@ import (
"strings"
)
func downloadAndExtract(url, dir string) (wasiSdkRoot string, err error) {
if _, err = os.Stat(dir); err == nil {
func checkDownloadAndExtract(url, dir string) (wasiSdkRoot string, err error) {
if _, err = os.Stat(dir); err != nil {
os.RemoveAll(dir)
}
tempDir := dir + ".temp"
os.RemoveAll(tempDir)
if err := os.MkdirAll(tempDir, 0755); err != nil {
return "", fmt.Errorf("failed to create temporary directory: %w", err)
}
tempDir := dir + ".temp"
os.RemoveAll(tempDir)
if err := os.MkdirAll(tempDir, 0755); err != nil {
return "", fmt.Errorf("failed to create temporary directory: %w", err)
}
urlPath := strings.Split(url, "/")
filename := urlPath[len(urlPath)-1]
localFile := filepath.Join(tempDir, filename)
if err = downloadFile(url, localFile); err != nil {
return "", fmt.Errorf("failed to download file: %w", err)
}
defer os.Remove(localFile)
urlPath := strings.Split(url, "/")
filename := urlPath[len(urlPath)-1]
localFile := filepath.Join(tempDir, filename)
if err = downloadFile(url, localFile); err != nil {
return "", fmt.Errorf("failed to download file: %w", err)
}
defer os.Remove(localFile)
if strings.HasSuffix(filename, ".tar.gz") || strings.HasSuffix(filename, ".tgz") {
err = extractTarGz(localFile, tempDir)
} else if strings.HasSuffix(filename, ".tar.xz") {
err = extractTarXz(localFile, tempDir)
} else {
return "", fmt.Errorf("unsupported archive format: %s", filename)
}
if err != nil {
return "", fmt.Errorf("failed to extract archive: %w", err)
}
if err = os.Rename(tempDir, dir); err != nil {
return "", fmt.Errorf("failed to rename directory: %w", err)
if strings.HasSuffix(filename, ".tar.gz") || strings.HasSuffix(filename, ".tgz") {
err = extractTarGz(localFile, tempDir)
} else if strings.HasSuffix(filename, ".tar.xz") {
err = extractTarXz(localFile, tempDir)
} else {
return "", fmt.Errorf("unsupported archive format: %s", filename)
}
if err != nil {
return "", fmt.Errorf("failed to extract archive: %w", err)
}
if err = os.Rename(tempDir, dir); err != nil {
return "", fmt.Errorf("failed to rename directory: %w", err)
}
}
wasiSdkRoot = filepath.Join(dir, "wasi-sdk-25.0-x86_64-macos")
return