Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Web update: count local and remote patches

  • Loading branch information...
commit ecf4453376e129bdd13a2c718bf4286d61fe2ac4 1 parent fa0831b
Sébastien Bourdeauducq authored July 03, 2011
40  src/flash.c
@@ -38,6 +38,8 @@
38 38
 #include "flashvalid.h"
39 39
 #include "version.h"
40 40
 #include "sysconfig.h"
  41
+#include "performance.h"
  42
+#include "patchpool.h"
41 43
 
42 44
 #include "flash.h"
43 45
 
@@ -145,6 +147,11 @@ static int download(const char *url, const char *filename)
145 147
 	}
146 148
 
147 149
 	fclose(fp);
  150
+	
  151
+	/* delete failed downloads */
  152
+	if(!ret)
  153
+		unlink(filename);
  154
+	
148 155
 	return ret;
149 156
 }
150 157
 
@@ -326,7 +333,7 @@ static void flash_terminate(int state)
326 333
 
327 334
 #define BASE_URL "http://www.milkymist.org/updates/current/"
328 335
 
329  
-static void get_versions()
  336
+static void get_versions(struct patchpool *local_patches, struct patchpool *remote_patches)
330 337
 {
331 338
 	char *b;
332 339
 	char *c;
@@ -336,6 +343,9 @@ static void get_versions()
336 343
 	available_application = unknown_version;
337 344
 	available_patches = -1;
338 345
 
  346
+	patchpool_add_files(local_patches, SIMPLE_PATCHES_FOLDER, "fnp");
  347
+	installed_patches = patchpool_count(local_patches);
  348
+
339 349
 	b = download_mem(BASE_URL "version-soc");
340 350
 	if(b == NULL)
341 351
 		flash_terminate(DOWNLOAD_STATE_ERROR_GET_VERSIONS);
@@ -357,6 +367,13 @@ static void get_versions()
357 367
 		*c = 0;
358 368
 	available_application = available_application_buf;
359 369
 	free(b);
  370
+	
  371
+	b = download_mem(BASE_URL "patchpool");
  372
+	if(b == NULL)
  373
+		flash_terminate(DOWNLOAD_STATE_ERROR_GET_VERSIONS);
  374
+	patchpool_add_multi(remote_patches, b);
  375
+	free(b);
  376
+	available_patches = patchpool_count(remote_patches);
360 377
 }
361 378
 
362 379
 static void download_images()
@@ -392,6 +409,12 @@ static void download_images()
392 409
 	}
393 410
 }
394 411
 
  412
+static void download_patches(struct patchpool *pp)
  413
+{
  414
+	/* TODO: ensure that the patch pool directory exists. Issue #25 precludes a simple mkdir(). */
  415
+	/* TODO */
  416
+}
  417
+
395 418
 static void flash_images()
396 419
 {
397 420
 	if(bitstream_name[0] != 0) {
@@ -426,14 +449,25 @@ static void flash_images()
426 449
 static rtems_task flash_task(rtems_task_argument argument)
427 450
 {
428 451
 	int task = (int)argument;
  452
+	struct patchpool local_patches;
  453
+	struct patchpool remote_patches;
429 454
 
430 455
 	switch(task) {
431 456
 		case ARG_GET_VERSIONS:
432 457
 		case ARG_WEB_UPDATE:
433  
-			get_versions();
434  
-			if(task == ARG_GET_VERSIONS)
  458
+			patchpool_init(&local_patches);
  459
+			patchpool_init(&remote_patches);
  460
+			get_versions(&local_patches, &remote_patches);
  461
+			if(task == ARG_GET_VERSIONS) {
  462
+				patchpool_free(&local_patches);
  463
+				patchpool_free(&remote_patches);
435 464
 				break;
  465
+			}
436 466
 			download_images();
  467
+			patchpool_diff(&remote_patches, &local_patches);
  468
+			download_patches(&remote_patches);
  469
+			patchpool_free(&local_patches);
  470
+			patchpool_free(&remote_patches);
437 471
 			/* fall through */
438 472
 		case ARG_FILE_UPDATE:
439 473
 			flash_images();
8  src/patchpool.c
@@ -107,8 +107,10 @@ void patchpool_add_multi(struct patchpool *pp, const char *entry)
107 107
 		offset = 0;
108 108
 		while((entry[offset] != '\n') && (entry[offset] != 0))
109 109
 			offset++;
110  
-		e = strndup(entry, offset);
111  
-		patchpool_add(pp, e);
  110
+		if(offset != 0) {
  111
+			e = strndup(entry, offset);
  112
+			patchpool_add(pp, e);
  113
+		}
112 114
 		if(entry[offset] == 0)
113 115
 			break;
114 116
 		else
@@ -134,7 +136,7 @@ void patchpool_add_files(struct patchpool *pp, const char *folder, const char *e
134 136
 		if(!S_ISDIR(s.st_mode)) {
135 137
 			c = strrchr(entry->d_name, '.');
136 138
 			if((c != NULL) && (strcmp(extension, c+1) == 0))
137  
-				patchpool_add(pp, entry->d_name);
  139
+				patchpool_add(pp, strdup(entry->d_name));
138 140
 		}
139 141
 	}
140 142
 	closedir(d);

0 notes on commit ecf4453

Please sign in to comment.
Something went wrong with that request. Please try again.