sohaib qamar / SWUpdate_RPC

Fork of SWUpdate by David Smart

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Mon Jan 19 13:33:47 2015 +0000
Parent:
18:5f7667d63a27
Child:
20:cf73b0d75bb7
Commit message:
Revise to detect full local file system.

Changed in this revision

SWUpdate.cpp Show annotated file Show diff for this revision Revisions of this file
SWUpdate.h Show annotated file Show diff for this revision Revisions of this file
--- a/SWUpdate.cpp	Sat Oct 11 17:27:46 2014 +0000
+++ b/SWUpdate.cpp	Mon Jan 19 13:33:47 2015 +0000
@@ -27,9 +27,15 @@
 
 static HTTPResult HTTPErrorCode;
 
-static bool PassesIntegrityCheck(const char * fname, int cksum, int fsize)
+typedef enum {
+    ok,
+    no_file,
+    bad_crc
+} Integrity_t;
+
+static Integrity_t PassesIntegrityCheck(const char * fname, int cksum, int fsize)
 {
-    int res = false;    // assume things go wrong...
+    Integrity_t res = bad_crc;    // assume things go wrong...
     int newCksum = 0;
     int newFSize = 0;
     FILE *fh = fopen(fname, "rb");
@@ -44,9 +50,10 @@
         fclose(fh);
         INFO("      Check(...,%d,%d)", newCksum, newFSize);
         if (newCksum == cksum && newFSize == fsize)
-            res = true;
+            res = ok;
     } else {
         WARN("failed to open %s.", fname);
+        res = no_file;
     }
     return res;
 }
@@ -186,7 +193,11 @@
                 HTTPFile latest(fwfn);
                 HTTPErrorCode = http.get(fqurl, &latest);
                 if (HTTPErrorCode == HTTP_OK) {
-                    if (PassesIntegrityCheck(fwfn, cksum, fsize)) {
+                    Integrity_t t = PassesIntegrityCheck(fwfn, cksum, fsize);
+                    if (t == no_file) {
+                        ERR("  *** No space on file system. ***");
+                        result |= SWUP_NO_SPACE;
+                    } else if (t == ok) {
                         if (!RemoveOtherBinFiles(nameroot, latest_ver)) {
                             ERR("  *** Failed to remove old version(s). ***");
                             result |= SWUP_OLD_STUCK;
@@ -211,7 +222,7 @@
                             WARN("Failed to update local version info in %s.", verfn);
                             result |= SWUP_VWRITE_FAILED;
                         }
-                    } else {
+                    } else /* t == bad_crc */ {
                         WARN("New file {%s} did not pass integrity check.", fwfn);
                         result |= SWUP_INTEGRITY_FAILED;
                     }
--- a/SWUpdate.h	Sat Oct 11 17:27:46 2014 +0000
+++ b/SWUpdate.h	Mon Jan 19 13:33:47 2015 +0000
@@ -136,6 +136,7 @@
     SWUP_VWRITE_FAILED    = 0x10,   ///< Can't open for write the version tracking file.
     SWUP_INTEGRITY_FAILED = 0x20,   ///< Integrity check of downloaded file failed.
     SWUP_HTTP_VER         = 0x40,   ///< HTTP get returned an error while trying to fetch the version file.
+    SWUP_NO_SPACE         = 0x80,   ///< No space on file system for new version.
 } SWUpdate_T;