Skip to content

Commit f3c20db

Browse files
Merge pull request #179 from ibuildthecloud/download
feat: sys.download path enhancements
2 parents 690cedb + b643cc8 commit f3c20db

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/builtin/builtin.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,14 @@ func SysAppend(ctx context.Context, env []string, input string) (string, error)
358358
return "", nil
359359
}
360360

361+
func urlExt(u string) string {
362+
url, err := url.Parse(u)
363+
if err != nil {
364+
return ""
365+
}
366+
return filepath.Ext(url.Path)
367+
}
368+
361369
func fixQueries(u string) (string, error) {
362370
url, err := url.Parse(u)
363371
if err != nil {
@@ -525,8 +533,17 @@ func SysDownload(ctx context.Context, env []string, input string) (_ string, err
525533
}
526534

527535
checkExists := true
536+
tmpDir := ""
537+
538+
if params.Location != "" {
539+
if s, err := os.Stat(params.Location); err == nil && s.IsDir() {
540+
tmpDir = params.Location
541+
params.Location = ""
542+
}
543+
}
544+
528545
if params.Location == "" {
529-
f, err := os.CreateTemp("", "gpt-download")
546+
f, err := os.CreateTemp(tmpDir, "gpt-download*"+urlExt(params.URL))
530547
if err != nil {
531548
return "", err
532549
}

0 commit comments

Comments
 (0)