From owner-p4-projects@FreeBSD.ORG Sun Aug 5 05:12:58 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CCA2F16A477; Sun, 5 Aug 2007 05:12:57 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4A0CE16A46D for ; Sun, 5 Aug 2007 05:12:57 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 41C4E13C4F9 for ; Sun, 5 Aug 2007 05:12:57 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l755Cvpm044539 for ; Sun, 5 Aug 2007 05:12:57 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l755CurM044536 for perforce@freebsd.org; Sun, 5 Aug 2007 05:12:56 GMT (envelope-from andrew@freebsd.org) Date: Sun, 5 Aug 2007 05:12:56 GMT Message-Id: <200708050512.l755CurM044536@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 124707 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Aug 2007 05:12:58 -0000 http://perforce.freebsd.org/chv.cgi?CH=124707 Change 124707 by andrew@andrew_hermies on 2007/08/05 05:12:46 Convert the patchlevel to a number when reading it from the tag file Add db_next_patch to the fbsd_update_db struct to record the patch level that will be installed when "freebsd-update install" is run or 0 if no patches are avaliable Use the value of db_next_patch to implement list_updates Affected files ... .. //depot/projects/soc2007/andrew-update/backend/facund-be.c#22 edit Differences ... ==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#22 (text+ko) ==== @@ -98,6 +98,8 @@ char *db_dir; int db_fd; + unsigned int db_next_patch; + char *db_tag_file; }; @@ -107,7 +109,7 @@ struct fbsd_tag_line { char *tag_platform; char *tag_release; - char *tag_patch; + unsigned int tag_patch; char tag_tindexhash[65]; char tag_eol[11]; }; @@ -120,7 +122,8 @@ { struct fbsd_tag_line *line; unsigned int len, item; - const char *str, *ptr; + char *num_buf; + const char *str, *ptr, *errstr; if (buf == NULL) return NULL; @@ -156,11 +159,16 @@ strlcpy(line->tag_release, str, len + 1); break; case 3: - line->tag_patch = malloc(len + 1); - if (line->tag_patch == NULL) + num_buf = malloc(len + 1); + if (num_buf == NULL) goto facund_decode_tag_line_exit; - strlcpy(line->tag_patch, str, len + 1); + strlcpy(num_buf, str, len + 1); + line->tag_patch = strtonum(num_buf, 0, UINT_MAX, + &errstr); + free(num_buf); + if (errstr != NULL) + goto facund_decode_tag_line_exit; break; case 4: if (len != 64) @@ -203,9 +211,6 @@ if (line->tag_release != NULL) free(line->tag_release); - if (line->tag_patch != NULL) - free(line->tag_patch); - free(line); } @@ -233,6 +238,8 @@ while (fgets(buf, sizeof buf, tag_fd) != NULL) { line = facund_tag_decode_line(buf); if (line != NULL) { + watched_db[pos].db_next_patch = + line->tag_patch; facund_tag_free(line); } } @@ -459,6 +466,8 @@ return -1; } + watched_db[pos].db_next_patch = 0; + ptr = next_ptr; if (ptr[0] == '\0') { return 0; @@ -714,30 +723,51 @@ args = facund_object_new_array(); for (pos = 0; base_dirs[pos] != NULL; pos++) { struct facund_object *pair, *item, *updates; + unsigned int i; + char *buf; + + for (i = 0; i < watched_db_count; i++) { + if (strcmp(watched_db[i].db_base, base_dirs[pos]) != 0) + continue; - pair = facund_object_new_array(); + printf("= %u\n", watched_db[i].db_next_patch); + if (watched_db[i].db_next_patch == 0) + break; + + pair = facund_object_new_array(); + + /* Add the directory to the start of the array */ + item = facund_object_new_string(); + facund_object_set_string(item, base_dirs[pos]); + facund_object_array_append(pair, item); - /* Add the directory to the start of the array */ - item = facund_object_new_string(); - facund_object_set_string(item, base_dirs[pos]); - facund_object_array_append(pair, item); + /* Add a list of updates to the array */ + updates = facund_object_new_array(); + item = facund_object_new_string(); + asprintf(&buf, "6.2-p%u", watched_db[i].db_next_patch); + if (buf == NULL) + return facund_response_new(id, 1, + "Malloc failed", NULL); - /* Add a list of updates to the array */ - updates = facund_object_new_array(); - item = facund_object_new_string(); - facund_object_set_string(item, "6.2-p2"); - facund_object_array_append(updates, item); - facund_object_array_append(pair, updates); + facund_object_set_string(item, buf); + free(buf); + facund_object_array_append(updates, item); + facund_object_array_append(pair, updates); - /* Add the directory on to the end of the arguments to return */ - facund_object_array_append(args, pair); + /* + * Add the directory on to the + * end of the arguments to return + */ + facund_object_array_append(args, pair); + break; + } + } + facund_object_print(args); + if (facund_object_array_size(args) == 0) { + facund_object_free(args); + args = NULL; } - printf("STUB: %s (base: %s, ports: %s)\n", __func__, - (get_base ? "yes" : "no"), (get_ports ? "yes" : "no")); - for (pos = 0; base_dirs[pos] != NULL; pos++) { - printf("Dir: %s\n", base_dirs[pos]); - } free(base_dirs); return facund_response_new(id, RESP_GOOD, "Success", args); }