From 9352ddab76a3860fe2afbb47cce43845a68e4801 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Wed, 28 Jul 2021 23:04:35 -0700 Subject: [PATCH] Changing version to 2.0.0 --- src/LatestFirmwareCache.cpp | 8 +++++--- src/LatestFirmwareCache.h | 2 +- src/storage_firmwares.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/LatestFirmwareCache.cpp b/src/LatestFirmwareCache.cpp index 80c0576..60cd9fd 100644 --- a/src/LatestFirmwareCache.cpp +++ b/src/LatestFirmwareCache.cpp @@ -16,17 +16,19 @@ namespace uCentral { void LatestFirmwareCache::Stop() { } - void LatestFirmwareCache::AddToCache(const std::string & DeviceType, const std::string &Revision, const std::string &Id, uint64_t TimeStamp) { + bool LatestFirmwareCache::AddToCache(const std::string & DeviceType, const std::string &Revision, const std::string &Id, uint64_t TimeStamp) { SubMutexGuard G(Mutex_); RevisionSet_.insert(Revision); DeviceSet_.insert(DeviceType); auto E = Cache_.find(DeviceType); - if((E==Cache_.end()) || (TimeStamp > E->second.TimeStamp)) { - Cache_[DeviceType] = LatestFirmwareCacheEntry{.Id=Id, + if((E==Cache_.end()) || (TimeStamp >= E->second.TimeStamp)) { + Cache_[DeviceType] = LatestFirmwareCacheEntry{ .Id=Id, .TimeStamp=TimeStamp, .Revision=Revision}; + return true; } + return false; } bool LatestFirmwareCache::FindLatestFirmware(const std::string &DeviceType, LatestFirmwareCacheEntry &Entry ) { diff --git a/src/LatestFirmwareCache.h b/src/LatestFirmwareCache.h index 93b85f2..36606d1 100644 --- a/src/LatestFirmwareCache.h +++ b/src/LatestFirmwareCache.h @@ -33,7 +33,7 @@ namespace uCentral { int Start() override; void Stop() override; - void AddToCache(const std::string & DeviceType, const std::string & Revision, const std::string &Id, uint64_t TimeStamp); + bool AddToCache(const std::string & DeviceType, const std::string & Revision, const std::string &Id, uint64_t TimeStamp); // void AddRevision(const std::string &Revision); bool FindLatestFirmware(const std::string &DeviceType, LatestFirmwareCacheEntry &Entry ); void DumpCache(); diff --git a/src/storage_firmwares.cpp b/src/storage_firmwares.cpp index 1ceb53d..b408606 100644 --- a/src/storage_firmwares.cpp +++ b/src/storage_firmwares.cpp @@ -63,17 +63,17 @@ namespace uCentral { // find the older software and change to latest = 0 F.id = Daemon()->CreateUUID(); - if(F.latest) - { + if(LatestFirmwareCache()->AddToCache(F.deviceType,F.revision,F.id,F.imageDate)) { + F.latest = true ; Poco::Data::Statement Update(Sess); std::string st{"UPDATE " + DBNAME_FIRMWARES + " SET latest=0 WHERE deviceType=? AND Latest=1"}; Update << ConvertParams(st), Poco::Data::Keywords::use(F.deviceType); Update.execute(); + } else { + F.latest = false; } - LatestFirmwareCache()->AddToCache(F.deviceType,F.revision,F.id,F.imageDate); - auto Notes = RESTAPI_utils::to_string(F.notes); std::string st{"INSERT INTO " + DBNAME_FIRMWARES + " (" + DBFIELDS_FIRMWARES_SELECT +