Skip to content

Commit

Permalink
Merge pull request #24 from ugwis/main
Browse files Browse the repository at this point in the history
Fix windows path issue
  • Loading branch information
ugwis authored Mar 25, 2024
2 parents ebf87ef + e9a485c commit 337a92b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
)

Expand All @@ -22,7 +21,7 @@ func FetchFile(url string) (string, error) {

hashedUrl := md5.New()
io.WriteString(hashedUrl, url)
cacheFilePath := filepath.Join(homeDir, ".cache", "awsdac", fmt.Sprintf("%x-%s", hashedUrl.Sum(nil), path.Base(url)))
cacheFilePath := filepath.Join(homeDir, ".cache", "awsdac", fmt.Sprintf("%x-%s", hashedUrl.Sum(nil), filepath.Base(url)))

// Check cached same URL resource
if _, err := os.Stat(cacheFilePath); err != nil {
Expand All @@ -37,7 +36,7 @@ func FetchFile(url string) (string, error) {
return "", fmt.Errorf("Failed to fetch file %s: http status %d", url, resp.StatusCode)
}

err = os.MkdirAll(path.Dir(cacheFilePath), os.ModePerm)
err = os.MkdirAll(filepath.Dir(cacheFilePath), os.ModePerm)
if err != nil {
return "", err
}
Expand All @@ -49,6 +48,9 @@ func FetchFile(url string) (string, error) {
defer out.Close()

_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
}
}
return cacheFilePath, nil
}
Expand All @@ -69,7 +71,7 @@ func ExtractZipFile(filePath string) (string, error) {
if _, err := io.Copy(hashedContent, f); err != nil {
return "", nil
}
cacheFilePath := filepath.Join(homeDir, ".cache", "awsdac", fmt.Sprintf("%x-%s", hashedContent.Sum(nil), path.Base(filePath)))
cacheFilePath := filepath.Join(homeDir, ".cache", "awsdac", fmt.Sprintf("%x-%s", hashedContent.Sum(nil), filepath.Base(filePath)))
if _, err := os.Stat(cacheFilePath); err != nil {

r, err := zip.OpenReader(filePath)
Expand All @@ -84,7 +86,7 @@ func ExtractZipFile(filePath string) (string, error) {

outputFilename := fmt.Sprintf("%s/%s", cacheFilePath, f.Name)

err = os.MkdirAll(path.Dir(outputFilename), os.ModePerm)
err = os.MkdirAll(filepath.Dir(outputFilename), os.ModePerm)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 337a92b

Please sign in to comment.