Пример #1
0
alpm_pkg_t *_alpm_pkghash_find(alpm_pkghash_t *hash, const char *name)
{
	alpm_list_t *lp;
	unsigned long name_hash;
	unsigned int position;

	if(name == NULL || hash == NULL) {
		return NULL;
	}

	name_hash = _alpm_hash_sdbm(name);

	position = name_hash % hash->buckets;

	while((lp = hash->hash_table[position]) != NULL) {
		alpm_pkg_t *info = lp->data;

		if(info->name_hash == name_hash && strcmp(info->name, name) == 0) {
			return info;
		}

		position += stride;
		while(position >= hash->buckets) {
			position -= hash->buckets;
		}
	}

	return NULL;
}
Пример #2
0
pmdepend_t *_alpm_splitdep(const char *depstring)
{
	pmdepend_t *depend;
	const char *ptr, *version = NULL;

	if(depstring == NULL) {
		return NULL;
	}

	CALLOC(depend, 1, sizeof(pmdepend_t), return NULL);

	/* Find a version comparator if one exists. If it does, set the type and
	 * increment the ptr accordingly so we can copy the right strings. */
	if((ptr = strstr(depstring, ">="))) {
		depend->mod = PM_DEP_MOD_GE;
		version = ptr + 2;
	} else if((ptr = strstr(depstring, "<="))) {
		depend->mod = PM_DEP_MOD_LE;
		version = ptr + 2;
	} else if((ptr = strstr(depstring, "="))) {
		/* Note: we must do =,<,> checks after <=, >= checks */
		depend->mod = PM_DEP_MOD_EQ;
		version = ptr + 1;
	} else if((ptr = strstr(depstring, "<"))) {
		depend->mod = PM_DEP_MOD_LT;
		version = ptr + 1;
	} else if((ptr = strstr(depstring, ">"))) {
		depend->mod = PM_DEP_MOD_GT;
		version = ptr + 1;
	} else {
		/* no version specified, leave version and ptr NULL */
		depend->mod = PM_DEP_MOD_ANY;
	}

	/* copy the right parts to the right places */
	STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
	depend->name_hash = _alpm_hash_sdbm(depend->name);
	if(version) {
		STRDUP(depend->version, version, return NULL);
	}

	return depend;
}
Пример #3
0
int load_package(pkg_t *pkg, int fd)
{
    struct archive *archive;
    struct file_t file;

    if (file_from_fd(&file, fd) < 0) {
        return -1;
    }

    archive = archive_read_new();
    archive_read_support_filter_all(archive);
    archive_read_support_format_all(archive);

    if (archive_read_open_memory(archive, file.mmap, file.st.st_size) != ARCHIVE_OK) {
        archive_read_free(archive);
        return -1;
    }

    bool found_pkginfo = false;
    struct archive_entry *entry;
    while (archive_read_next_header(archive, &entry) == ARCHIVE_OK && !found_pkginfo) {
        const char *entry_name = archive_entry_pathname(entry);
        const mode_t mode = archive_entry_mode(entry);

        if (S_ISREG(mode) && streq(entry_name, ".PKGINFO")) {
            read_pkginfo(archive, pkg);
            found_pkginfo = true;
        }
    }

    archive_read_close(archive);
    archive_read_free(archive);

    if (found_pkginfo) {
        pkg->size = file.st.st_size;
        pkg->mtime = file.st.st_mtime;
        pkg->name_hash = _alpm_hash_sdbm(pkg->name);
        return 0;
    }

    return -1;
}