diff --git a/manager/tasks.py b/manager/tasks.py index 548b045..0538b32 100644 --- a/manager/tasks.py +++ b/manager/tasks.py @@ -14,9 +14,6 @@ import datetime @shared_task def mkfirmware(device, path): - if device.firmware and device.firmware > device.model.firmware and device.firmware > device.changed and glob.glob("%s/%s.bin" % (path, device.id)): - return True - BEFORE = os.getcwd() DEVICEDIR = "/opt/vpnmanager/device-config/%i/" % device.model.id SRCDIR = "/opt/vpnmanager/imagebuilder/%i/" % device.model.id @@ -87,8 +84,6 @@ def mkfirmware(device, path): os.system("rm -rf " + SRCDIR + "/files/") os.system("rm " + SRCDIR + "/bin/targets/ar71xx/generic/*") - device.firmware = datetime.datetime.now() - device.save() return True except Exception as e: diff --git a/manager/views.py b/manager/views.py index e14ba11..17edeb3 100644 --- a/manager/views.py +++ b/manager/views.py @@ -75,12 +75,13 @@ def update(request): device = get_object_or_404(Device, secret=request.POST.get("secret", "")) try: - if not mkfirmware.delay(device, FWDIR).get(timeout=300): + if not mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300): return HttpResponse(status=503) except TimeoutError: return HttpResponse(status=503) sigUpdateDevice(device.serial, None, False) + device.firmware = datetime.datetime.now() device.update = False device.save() @@ -311,11 +312,13 @@ def getconfig(request, device_id): FWDIR = "/opt/vpnmanager/images/" device = get_object_or_404(Device, id=device_id) + files = glob.glob("%s/%s.bin" % (FWDIR, device_id)) - if not mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300): + if not ((files and datetime.datetime.fromtimestamp(os.path.getmtime(files[0]), timezone.get_current_timezone()) > device.model.firmware) or mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300)): return HttpResponse(status=503) sigUpdateDevice(device.serial, None, False) + device.firmware = datetime.datetime.now() device.update = False device.save()