Appease the linter

This commit is contained in:
Justin Hawkins 2023-03-15 04:45:10 +10:30
parent c8f10e01c7
commit 4909f63c93
3 changed files with 71 additions and 22 deletions

View File

@ -94,7 +94,6 @@ func (cs *ConfigService) LoadDefaultConfig() {
cs.Config = &defaultConfig
return
}
func (c *Config) ProfileCalled(name string) *DownloadProfile {
@ -319,6 +318,9 @@ func (cs *ConfigService) WriteConfig() {
}
defer file.Close()
file.Write(s)
_, err = file.Write(s)
if err != nil {
log.Fatalf("could not write config file %s: %s", path, err)
}
file.Close()
}

View File

@ -250,7 +250,10 @@ func (dl *Download) Stop() {
dl.Lock.Lock()
defer dl.Lock.Unlock()
dl.Log = append(dl.Log, "aborted by user")
dl.Process.Kill()
err := dl.Process.Kill()
if err != nil {
log.Printf("could not send kill to process: %s", err)
}
}
// domain returns a domain for this Download. Download should be locked.
@ -335,19 +338,30 @@ func (dl *Download) Begin() {
}()
wg.Wait()
cmd.Wait()
err = cmd.Wait()
dl.Lock.Lock()
log.Printf("Process finished for id: %d (%v)", dl.Id, cmd)
if err != nil {
log.Printf("process failed for id: %d: %s", dl.Id, err)
dl.State = STATE_COMPLETE
dl.Finished = true
dl.FinishedTS = time.Now()
dl.ExitCode = cmd.ProcessState.ExitCode()
if dl.ExitCode != 0 {
dl.State = STATE_FAILED
dl.Finished = true
dl.FinishedTS = time.Now()
dl.ExitCode = cmd.ProcessState.ExitCode()
} else {
log.Printf("process finished for id: %d (%v)", dl.Id, cmd)
dl.State = STATE_COMPLETE
dl.Finished = true
dl.FinishedTS = time.Now()
dl.ExitCode = cmd.ProcessState.ExitCode()
if dl.ExitCode != 0 {
dl.State = STATE_FAILED
}
}
dl.Lock.Unlock()

55
main.go
View File

@ -101,7 +101,10 @@ func main() {
// check for a new version every 4 hours
go func() {
for {
versionInfo.UpdateGitHubVersion()
err := versionInfo.UpdateGitHubVersion()
if err != nil {
log.Printf("could not get version info: %s", err)
}
time.Sleep(time.Hour * 4)
}
}()
@ -120,7 +123,10 @@ func main() {
func versionRESTHandler(w http.ResponseWriter, r *http.Request) {
if versionInfo.GetInfo().GithubVersionFetched {
b, _ := json.Marshal(versionInfo.GetInfo())
w.Write(b)
_, err := w.Write(b)
if err != nil {
log.Printf("could not write to client: %s", err)
}
} else {
w.WriteHeader(400)
}
@ -172,7 +178,10 @@ func staticHandler(w http.ResponseWriter, r *http.Request) {
return
}
w.WriteHeader(http.StatusOK)
io.Copy(w, f)
_, err = io.Copy(w, f)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
w.WriteHeader(http.StatusNotFound)
@ -208,13 +217,19 @@ func configRESTHandler(w http.ResponseWriter, r *http.Request) {
errorRes := errorResponse{Success: false, Error: err.Error()}
errorResB, _ := json.Marshal(errorRes)
w.WriteHeader(400)
w.Write(errorResB)
_, err = w.Write(errorResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
configService.WriteConfig()
}
b, _ := json.Marshal(configService.Config)
w.Write(b)
_, err := w.Write(b)
if err != nil {
log.Printf("could not write config to client: %s", err)
}
}
func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
@ -256,7 +271,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
errorRes := errorResponse{Success: false, Error: err.Error()}
errorResB, _ := json.Marshal(errorRes)
w.WriteHeader(400)
w.Write(errorResB)
_, err = w.Write(errorResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
@ -275,7 +293,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
succRes := successResponse{Success: true, Message: "download started"}
succResB, _ := json.Marshal(succRes)
w.Write(succResB)
_, err = w.Write(succResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
@ -290,7 +311,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
succRes := successResponse{Success: true, Message: "destination changed"}
succResB, _ := json.Marshal(succRes)
w.Write(succResB)
_, err = w.Write(succResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
@ -299,7 +323,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
thisDownload.Stop()
succRes := successResponse{Success: true, Message: "download stopped"}
succResB, _ := json.Marshal(succRes)
w.Write(succResB)
_, err = w.Write(succResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
}
@ -310,7 +337,10 @@ func fetchInfoOneRESTHandler(w http.ResponseWriter, r *http.Request) {
b, _ := json.Marshal(thisDownload)
w.Write(b)
_, err = w.Write(b)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
} else {
http.NotFound(w, r)
@ -323,7 +353,10 @@ func fetchInfoRESTHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
panic(err)
}
w.Write(b)
_, err = w.Write(b)
if err != nil {
log.Printf("could not write to client: %s", err)
}
}
func fetchHandler(w http.ResponseWriter, r *http.Request) {