-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from safing/develop
Fix clean shutdown with portmaster-control
- Loading branch information
Showing
6 changed files
with
174 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/safing/portbase/utils" | ||
"github.com/safing/portmaster/updates" | ||
) | ||
|
||
func getFile(identifier string) (*updates.File, error) { | ||
func getFile(opts *Options) (*updates.File, error) { | ||
// get newest local file | ||
updates.LoadLatest() | ||
file, err := updates.GetPlatformFile(identifier) | ||
|
||
file, err := updates.GetLocalPlatformFile(opts.Identifier) | ||
if err == nil { | ||
return file, nil | ||
} | ||
if err != updates.ErrNotFound { | ||
return nil, err | ||
} | ||
|
||
fmt.Printf("%s downloading %s...\n", logPrefix, identifier) | ||
|
||
// if no matching file exists, load index | ||
err = updates.LoadIndexes() | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
// create dirs | ||
err = utils.EnsureDirectory(updateStoragePath, 0755) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// download indexes | ||
err = updates.CheckForUpdates() | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
// download | ||
if opts.AllowDownload { | ||
fmt.Printf("%s downloading %s...\n", logPrefix, 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 | ||
} | ||
|
||
// get file | ||
return updates.GetPlatformFile(identifier) | ||
// wait for 30 seconds | ||
fmt.Printf("%s waiting for download of %s (by Portmaster Core) to complete...\n", logPrefix, 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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.