mirror of
https://github.com/safing/portbase
synced 2025-09-04 19:50:18 +00:00
Fix report downloads deleting pending updates
This commit is contained in:
parent
d6687ecbad
commit
c9d77682f8
4 changed files with 21 additions and 11 deletions
|
@ -290,7 +290,7 @@ func (api *DatabaseAPI) handleGet(opID []byte, key string) {
|
||||||
|
|
||||||
r, err := api.db.Get(key)
|
r, err := api.db.Get(key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data, err = marshalRecord(r, true)
|
data, err = MarshalRecord(r, true)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.send(opID, dbMsgTypeError, err.Error(), nil)
|
api.send(opID, dbMsgTypeError, err.Error(), nil)
|
||||||
|
@ -348,7 +348,7 @@ func (api *DatabaseAPI) processQuery(opID []byte, q *query.Query) (ok bool) {
|
||||||
// process query feed
|
// process query feed
|
||||||
if r != nil {
|
if r != nil {
|
||||||
// process record
|
// process record
|
||||||
data, err := marshalRecord(r, true)
|
data, err := MarshalRecord(r, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
|
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
|
||||||
continue
|
continue
|
||||||
|
@ -425,7 +425,7 @@ func (api *DatabaseAPI) processSub(opID []byte, sub *database.Subscription) {
|
||||||
// process sub feed
|
// process sub feed
|
||||||
if r != nil {
|
if r != nil {
|
||||||
// process record
|
// process record
|
||||||
data, err := marshalRecord(r, true)
|
data, err := MarshalRecord(r, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
|
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
|
||||||
continue
|
continue
|
||||||
|
@ -629,9 +629,9 @@ func (api *DatabaseAPI) handleDelete(opID []byte, key string) {
|
||||||
api.send(opID, dbMsgTypeSuccess, emptyString, nil)
|
api.send(opID, dbMsgTypeSuccess, emptyString, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// marsharlRecords locks and marshals the given record, additionally adding
|
// MarshalRecords locks and marshals the given record, additionally adding
|
||||||
// metadata and returning it as json.
|
// metadata and returning it as json.
|
||||||
func marshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
|
func MarshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,7 @@ func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
var rec record.Record
|
var rec record.Record
|
||||||
rec, err = e.RecordFunc(apiRequest)
|
rec, err = e.RecordFunc(apiRequest)
|
||||||
if err == nil && r != nil {
|
if err == nil && r != nil {
|
||||||
responseData, err = marshalRecord(rec, false)
|
responseData, err = MarshalRecord(rec, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
case e.HandlerFunc != nil:
|
case e.HandlerFunc != nil:
|
||||||
|
|
|
@ -93,7 +93,7 @@ func (rv *ResourceVersion) String() string {
|
||||||
return rv.VersionNumber
|
return rv.VersionNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
// SemVer returns the semantiv version of the resource.
|
// SemVer returns the semantic version of the resource.
|
||||||
func (rv *ResourceVersion) SemVer() *semver.Version {
|
func (rv *ResourceVersion) SemVer() *semver.Version {
|
||||||
return rv.semVer
|
return rv.semVer
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ const (
|
||||||
StateFetching = "fetching" // Fetching a single file.
|
StateFetching = "fetching" // Fetching a single file.
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegistryState describtes the registry state.
|
// RegistryState describes the registry state.
|
||||||
type RegistryState struct {
|
type RegistryState struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
reg *ResourceRegistry
|
reg *ResourceRegistry
|
||||||
|
@ -58,7 +58,7 @@ type UpdateState struct {
|
||||||
LastDownloadAt *time.Time
|
LastDownloadAt *time.Time
|
||||||
// LastDownloadError holds the error of the last download.
|
// LastDownloadError holds the error of the last download.
|
||||||
LastDownloadError error
|
LastDownloadError error
|
||||||
// LastDownload holds the resources that we downloaded the last time udpates
|
// LastDownload holds the resources that we downloaded the last time updates
|
||||||
// were downloaded.
|
// were downloaded.
|
||||||
LastDownload []string
|
LastDownload []string
|
||||||
|
|
||||||
|
@ -145,8 +145,18 @@ func (s *RegistryState) ReportDownloads(downloaded []string, failed error) {
|
||||||
s.Updates.LastDownloadError = failed
|
s.Updates.LastDownloadError = failed
|
||||||
s.Updates.LastDownload = downloaded
|
s.Updates.LastDownload = downloaded
|
||||||
|
|
||||||
// Reset pending downloads, as they have now been downloaded.
|
// Remote downloaded resources from the pending list.
|
||||||
s.Updates.PendingDownload = nil
|
var newPendingDownload []string
|
||||||
|
outer:
|
||||||
|
for _, pend := range s.Updates.PendingDownload {
|
||||||
|
for _, down := range downloaded {
|
||||||
|
if pend == down {
|
||||||
|
continue outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newPendingDownload = append(newPendingDownload, pend)
|
||||||
|
}
|
||||||
|
s.Updates.PendingDownload = newPendingDownload
|
||||||
|
|
||||||
if failed == nil {
|
if failed == nil {
|
||||||
s.Updates.LastSuccessAt = &now
|
s.Updates.LastSuccessAt = &now
|
||||||
|
|
Loading…
Add table
Reference in a new issue