safing-portmaster/pmctl/get.go
Daniel c6083fc464 Finish windows support
- Fix service creation
- Singleton lock
- Control error/logging
- Revamp run/service interaction
- Add option to turn off stdout/stderr output (for Windows Service)
- Use log instead of fmt.Print*
2019-07-24 09:22:16 +02:00

61 lines
1.2 KiB
Go

package main
import (
"errors"
"log"
"time"
"github.com/safing/portmaster/updates"
)
func getFile(opts *Options) (*updates.File, error) {
// get newest local file
updates.LoadLatest()
file, err := updates.GetLocalPlatformFile(opts.Identifier)
if err == nil {
return file, nil
}
if err != updates.ErrNotFound {
return nil, err
}
// download
if opts.AllowDownload {
log.Printf("downloading %s...\n", opts.Identifier)
// download indexes
err = updates.UpdateIndexes()
if err != nil {
return nil, err
}
// download file
file, err := updates.GetPlatformFile(opts.Identifier)
if err != nil {
return nil, err
}
return file, nil
}
// wait for 30 seconds
log.Printf("waiting for download of %s (by Portmaster Core) to complete...\n", opts.Identifier)
// try every 0.5 secs
for tries := 0; tries < 60; tries++ {
time.Sleep(500 * time.Millisecond)
// reload local files
updates.LoadLatest()
// get file
file, err := updates.GetLocalPlatformFile(opts.Identifier)
if err == nil {
return file, nil
}
if err != updates.ErrNotFound {
return nil, err
}
}
return nil, errors.New("please try again later or check the Portmaster logs")
}