celix_status_t bundleRevision_create(framework_logger_pt loggera, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) { celix_status_t status = CELIX_SUCCESS; bundle_revision_pt revision = NULL; revision = (bundle_revision_pt) malloc(sizeof(*revision)); if (!revision) { status = CELIX_ENOMEM; } else { // TODO: This overwrites an existing revision, is this supposed to happen? int state = mkdir(root, S_IRWXU); if ((state != 0) && (errno != EEXIST)) { free(revision); status = CELIX_FILE_IO_EXCEPTION; } else { if (inputFile != NULL) { status = extractBundle(inputFile, root); } else if (strcmp(location, "inputstream:") != 0) { // TODO how to handle this correctly? // If location != inputstream, extract it, else ignore it and assume this is a cache entry. status = extractBundle(location, root); } status = CELIX_DO_IF(status, arrayList_create(&(revision->libraryHandles))); if (status == CELIX_SUCCESS) { revision->revisionNr = revisionNr; revision->root = strdup(root); revision->location = strdup(location); revision->logger = loggera; *bundle_revision = revision; char manifest[512]; snprintf(manifest, sizeof(manifest), "%s/META-INF/MANIFEST.MF", revision->root); status = manifest_createFromFile(manifest, &revision->manifest); } else { free(revision); } } } framework_logIfError(logger, status, NULL, "Failed to create revision"); return status; }
static void * APR_THREAD_FUNC deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin) { deployment_admin_pt admin = deploymentAdmin; /*first poll send framework started audit event, note this will register the target in Apache ACE*/ deploymentAdmin_updateAuditPool(admin, DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED); while (admin->running) { //poll ace array_list_pt versions = NULL; deploymentAdmin_readVersions(admin, &versions); char *last = arrayList_get(versions, arrayList_size(versions) - 1); if (last != NULL) { if (admin->current == NULL || strcmp(last, admin->current) > 0) { char *request = NULL; if (admin->current == NULL) { request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } else { // We do not yet support fix packages //request = apr_pstrcat(admin->pool, VERSIONS, "/", last, "?current=", admin->current, NULL); request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } char inputFile[256]; inputFile[0] = '\0'; char *test = inputFile; celix_status_t status = deploymentAdmin_download(request, &test); if (status == CELIX_SUCCESS) { bundle_pt bundle = NULL; bundleContext_getBundle(admin->context, &bundle); char *entry = NULL; bundle_getEntry(bundle, "/", &entry); // Handle file char tmpDir[256]; char uuidStr[128]; apr_uuid_t tmpUuid; apr_uuid_get(&tmpUuid); apr_uuid_format(uuidStr, &tmpUuid); sprintf(tmpDir, "%s%s", entry, uuidStr); apr_dir_make(tmpDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool); // TODO: update to use bundle cache DataFile instead of module entries. unzip_extractDeploymentPackage(test, tmpDir); char *manifest = apr_pstrcat(admin->pool, tmpDir, "/META-INF/MANIFEST.MF", NULL); manifest_pt mf = NULL; manifest_createFromFile(manifest, &mf); deployment_package_pt source = NULL; deploymentPackage_create(admin->pool, admin->context, mf, &source); char *name = NULL; deploymentPackage_getName(source, &name); char *repoDir = apr_pstrcat(admin->pool, entry, "repo", NULL); apr_dir_make(repoDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool); char *repoCache = apr_pstrcat(admin->pool, entry, "repo/", name, NULL); deploymentAdmin_deleteTree(repoCache, admin->pool); apr_status_t stat = apr_file_rename(tmpDir, repoCache, admin->pool); if (stat != APR_SUCCESS) { printf("No success\n"); } deployment_package_pt target = hashMap_get(admin->packages, name); if (target == NULL) { // target = empty package } deploymentAdmin_stopDeploymentPackageBundles(admin, target); deploymentAdmin_updateDeploymentPackageBundles(admin, source); deploymentAdmin_startDeploymentPackageCustomizerBundles(admin, source, target); deploymentAdmin_processDeploymentPackageResources(admin, source); deploymentAdmin_dropDeploymentPackageResources(admin, source, target); deploymentAdmin_dropDeploymentPackageBundles(admin, source, target); deploymentAdmin_startDeploymentPackageBundles(admin, source); deploymentAdmin_deleteTree(repoCache, admin->pool); deploymentAdmin_deleteTree(tmpDir, admin->pool); remove(test); admin->current = strdup(last); hashMap_put(admin->packages, name, source); } } } sleep(5); } apr_thread_exit(thd, APR_SUCCESS); return NULL; }