Overview
Comment: | Reduced redundant code |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
041086f3fbf180deb7f0498bef34df35 |
User & Date: | rkeene on 2014-09-10 04:01:07 |
Other Links: | manifest | tags |
Context
2014-09-10
| ||
04:02 | Reorganized check-in: 1f01cf90b5 user: rkeene tags: trunk | |
04:01 | Reduced redundant code check-in: 041086f3fb user: rkeene tags: trunk | |
2014-09-09
| ||
08:23 | Added a default time to psuedo entries check-in: ef5acff5c9 user: rkeene tags: trunk | |
Changes
Modified appfs.c from [799a556739] to [3c07efd857].
︙ | ︙ | |||
326 327 328 329 330 331 332 | type *obj, *next; \ for (obj = head; obj; obj = next) { \ next = obj->_next; \ ckfree((void *) obj); \ } \ } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | type *obj, *next; \ for (obj = head; obj; obj = next) { \ next = obj->_next; \ ckfree((void *) obj); \ } \ } appfs_free_list_type(children, struct appfs_children) static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) { struct appfs_children **head_p, *obj; head_p = _head; obj = (void *) ckalloc(sizeof(*obj)); |
︙ | ︙ | |||
495 496 497 498 499 500 501 502 503 504 505 506 507 508 | if (head != NULL) { *children_count_p = head->counter + 1; } return(head); } static int appfs_lookup_package_hash_cb(void *_retval, int columns, char **values, char **names) { char **retval = _retval; *retval = strdup(values[0]); return(0); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | if (head != NULL) { *children_count_p = head->counter + 1; } return(head); } struct appfs_sqlite3_query_cb_handle { struct appfs_children *head; int argc; const char *fmt; }; static int appfs_sqlite3_query_cb(void *_cb_handle, int columns, char **values, char **names) { struct appfs_sqlite3_query_cb_handle *cb_handle; struct appfs_children *obj; cb_handle = _cb_handle; obj = (void *) ckalloc(sizeof(*obj)); switch (cb_handle->argc) { case 1: snprintf(obj->name, sizeof(obj->name), cb_handle->fmt, values[0]); break; case 2: snprintf(obj->name, sizeof(obj->name), cb_handle->fmt, values[0], values[1]); break; case 3: snprintf(obj->name, sizeof(obj->name), cb_handle->fmt, values[0], values[1], values[2]); break; case 4: snprintf(obj->name, sizeof(obj->name), cb_handle->fmt, values[0], values[1], values[2], values[3]); break; } if (cb_handle->head == NULL) { obj->counter = 0; } else { obj->counter = cb_handle->head->counter + 1; } obj->_next = cb_handle->head; cb_handle->head = obj; return(0); } static struct appfs_children *appfs_sqlite3_query(char *sql, int argc, const char *fmt, int *results_count_p) { struct appfs_sqlite3_query_cb_handle cb_handle; int sqlite_ret; if (results_count_p == NULL) { return(NULL); } if (sql == NULL) { APPFS_DEBUG("Call to sqlite3_mprintf probably failed."); return(NULL); } if (fmt == NULL) { fmt = "%s"; } cb_handle.head = NULL; cb_handle.argc = argc; cb_handle.fmt = fmt; APPFS_DEBUG("SQL: %s", sql); sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_sqlite3_query_cb, &cb_handle, NULL); sqlite3_free(sql); if (sqlite_ret != SQLITE_OK) { APPFS_DEBUG("Call to sqlite3_exec failed."); return(NULL); } if (cb_handle.head != NULL) { *results_count_p = cb_handle.head->counter + 1; } return(cb_handle.head); } static int appfs_lookup_package_hash_cb(void *_retval, int columns, char **values, char **names) { char **retval = _retval; *retval = strdup(values[0]); return(0); |
︙ | ︙ | |||
643 644 645 646 647 648 649 650 651 | if (pathinfo->type == APPFS_PATHTYPE_INVALID) { return(-ENOENT); } return(0); } /* Get information about a path, and optionally list children */ static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | < > | | > | > > > > > | | < | < < < < < | | | < < < | > | < | | | < < < < < < < < < < < < | < | < | < < < < < | < < < < < < | < < < < < < < < < < < < | < < < < | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | if (pathinfo->type == APPFS_PATHTYPE_INVALID) { return(-ENOENT); } return(0); } static int appfs_get_path_info_sql(char *sql, int argc, const char *fmt, struct appfs_pathinfo *pathinfo, struct appfs_children **children) { struct appfs_children *node, *dir_children, *dir_child; int dir_children_count = 0; dir_children = appfs_sqlite3_query(sql, argc, fmt, &dir_children_count); if (dir_children == NULL || dir_children_count == 0) { return(-ENOENT); } /* Request for a single hostname */ pathinfo->type = APPFS_PATHTYPE_DIRECTORY; pathinfo->typeinfo.dir.childcount = dir_children_count; pathinfo->time = globalThread.boottime; if (children) { for (dir_child = dir_children; dir_child; dir_child = dir_child->_next) { node = (void *) ckalloc(sizeof(*node)); node->_next = *children; strcpy(node->name, dir_child->name); *children = node; } } appfs_free_list_children(dir_children); return(0); } /* Get information about a path, and optionally list children */ static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) { struct appfs_children *dir_children; appfs_os_t os_val; appfs_cpuArch_t cpuArch_val; char *hostname, *packagename, *os_cpuArch, *os, *cpuArch, *version; char *path, *path_s; char *package_hash; char *sql; int files_count; int fileinfo_ret, retval; if (children) { *children = NULL; } if (_path == NULL) { return(-ENOENT); } if (_path[0] != '/') { return(-ENOENT); } if (_path[1] == '\0') { /* Request for the root directory */ pathinfo->hostname[0] = '\0'; sql = sqlite3_mprintf("SELECT DISTINCT hostname FROM packages;"); retval = appfs_get_path_info_sql(sql, 1, NULL, pathinfo, children); /* The root directory always exists, even if it has no subordinates */ if (retval != 0) { pathinfo->type = APPFS_PATHTYPE_DIRECTORY; pathinfo->typeinfo.dir.childcount = 0; pathinfo->time = globalThread.boottime; retval = 0; } return(retval); } path = strdup(_path); path_s = path; hostname = path + 1; packagename = strchr(hostname, '/'); if (packagename != NULL) { *packagename = '\0'; packagename++; } snprintf(pathinfo->hostname, sizeof(pathinfo->hostname), "%s", hostname); if (packagename == NULL) { appfs_update_index(hostname); sql = sqlite3_mprintf("SELECT DISTINCT package FROM packages WHERE hostname = %Q;", hostname); free(path_s); return(appfs_get_path_info_sql(sql, 1, NULL, pathinfo, children)); } os_cpuArch = strchr(packagename, '/'); if (os_cpuArch != NULL) { *os_cpuArch = '\0'; os_cpuArch++; } if (os_cpuArch == NULL) { appfs_update_index(hostname); sql = sqlite3_mprintf("SELECT DISTINCT os, cpuArch FROM packages WHERE hostname = %Q AND package = %Q;", hostname, packagename); free(path_s); return(appfs_get_path_info_sql(sql, 2, "%s-%s", pathinfo, children)); } version = strchr(os_cpuArch, '/'); if (version != NULL) { *version = '\0'; version++; } |
︙ | ︙ | |||
794 795 796 797 798 799 800 | cpuArch_val = APPFS_CPU_UNKNOWN; } os_val = appfs_convert_os_fromString(os); if (version == NULL) { /* Request for version list for a package on an OS/CPU */ | < < | < < < < < < | < < | < < < < < < < < < < < < < < < < < < | < < < | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | cpuArch_val = APPFS_CPU_UNKNOWN; } os_val = appfs_convert_os_fromString(os); if (version == NULL) { /* Request for version list for a package on an OS/CPU */ appfs_update_index(hostname); sql = sqlite3_mprintf("SELECT DISTINCT version FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q and cpuArch = %Q;", hostname, packagename, os, cpuArch); free(path_s); return(appfs_get_path_info_sql(sql, 1, NULL, pathinfo, children)); } path = strchr(version, '/'); if (path == NULL) { path = ""; } else { *path = '\0'; path++; } |
︙ | ︙ | |||
855 856 857 858 859 860 861 862 863 864 865 866 867 868 | if (package_hash == NULL) { free(path_s); return(-ENOENT); } APPFS_DEBUG(" ... which hash a hash of %s", package_hash); if (strcmp(path, "") == 0) { pathinfo->type = APPFS_PATHTYPE_DIRECTORY; pathinfo->time = globalThread.boottime; } else { fileinfo_ret = appfs_getfileinfo(hostname, package_hash, path, pathinfo); if (fileinfo_ret != 0) { | > > | 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | if (package_hash == NULL) { free(path_s); return(-ENOENT); } APPFS_DEBUG(" ... which hash a hash of %s", package_hash); appfs_update_manifest(hostname, package_hash); if (strcmp(path, "") == 0) { pathinfo->type = APPFS_PATHTYPE_DIRECTORY; pathinfo->time = globalThread.boottime; } else { fileinfo_ret = appfs_getfileinfo(hostname, package_hash, path, pathinfo); if (fileinfo_ret != 0) { |
︙ | ︙ |