Compare commits

...

3 Commits

Author SHA1 Message Date
92c4f0c77a
fix file exists check
All checks were successful
builder / build (push) Successful in 19s
deployer / go-releaser (push) Successful in 29s
2024-07-20 19:26:22 -07:00
c243b76969
print script output if executed
All checks were successful
builder / build (push) Successful in 19s
deployer / go-releaser (push) Successful in 29s
2024-07-20 19:20:20 -07:00
538e2f69de
fix
All checks were successful
builder / build (push) Successful in 20s
deployer / go-releaser (push) Successful in 35s
2024-07-20 11:01:41 -07:00
2 changed files with 13 additions and 11 deletions

View File

@ -8,9 +8,7 @@ before:
- go mod tidy - go mod tidy
builds: builds:
- env: - goos:
- CGO_ENABLED=0
goos:
- linux - linux
- windows - windows
- darwin - darwin
@ -18,7 +16,7 @@ builds:
- goos: windows - goos: windows
goarch: "386" goarch: "386"
ldflags: ldflags:
- -s -w -X git.asdf.cafe/abs3nt/wallhaven_dl/main.Version={{.Version}} - -s -w -X main.Version={{.Version}}
archives: archives:
- format: tar.gz - format: tar.gz

18
main.go
View File

@ -188,19 +188,23 @@ func getOrDownload(results *wallhaven.SearchResults, r *rand.Rand, downloadPath
} }
result := results.Data[r.Intn(len(results.Data))] result := results.Data[r.Intn(len(results.Data))]
fullPath := path.Join(downloadPath, path.Base(result.Path)) fullPath := path.Join(downloadPath, path.Base(result.Path))
if _, err := os.Stat(fullPath); err != nil { _, err := os.Stat(fullPath)
if err == nil {
return fullPath, nil
}
if os.IsNotExist(err) {
err = result.Download(path.Join(downloadPath)) err = result.Download(path.Join(downloadPath))
if err != nil { if err != nil {
return "", err return "", err
} }
return fullPath, nil
} }
return fullPath, nil return "", err
} }
func runScript(imgPath, script string) error { func runScript(imgPath, script string) error {
_, err := exec.Command(script, imgPath).Output() cmd := exec.Command(script, imgPath)
if err != nil { cmd.Stdout = os.Stdout
return err cmd.Stderr = os.Stderr
} return cmd.Run()
return nil
} }