2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* package.c
|
2006-10-15 15:31:03 -04:00
|
|
|
*
|
2012-02-20 07:53:03 -05:00
|
|
|
* Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005, 2006 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-02-10 18:44:39 -05:00
|
|
|
#include <sys/types.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
2007-02-09 16:54:57 -05:00
|
|
|
#include "package.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "alpm_list.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2006-11-20 04:10:23 -05:00
|
|
|
#include "db.h"
|
2007-10-29 22:06:13 -04:00
|
|
|
#include "delta.h"
|
2006-11-20 04:10:23 -05:00
|
|
|
#include "handle.h"
|
2007-11-13 00:01:14 -05:00
|
|
|
#include "deps.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** \addtogroup alpm_packages Package Functions
|
|
|
|
* @brief Functions to manipulate libalpm packages
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Free a package. */
|
2011-06-28 09:26:39 -04:00
|
|
|
int SYMEXPORT alpm_pkg_free(alpm_pkg_t *pkg)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2007-06-03 23:57:38 -04:00
|
|
|
|
|
|
|
/* Only free packages loaded in user space */
|
2008-05-11 13:00:18 -04:00
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
2007-06-03 23:57:38 -04:00
|
|
|
_alpm_pkg_free(pkg);
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Check the integrity (with md5) of a package from the sync cache. */
|
2011-06-28 09:26:39 -04:00
|
|
|
int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2007-08-20 13:28:51 -04:00
|
|
|
char *fpath;
|
2008-02-26 18:50:17 -05:00
|
|
|
int retval;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
/* We only inspect packages from sync repositories */
|
2011-06-14 11:01:08 -04:00
|
|
|
ASSERT(pkg->origin == PKG_FROM_SYNCDB,
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-09-02 23:07:06 -04:00
|
|
|
fpath = _alpm_filecache_find(pkg->handle, pkg->filename);
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2012-02-19 23:24:35 -05:00
|
|
|
retval = _alpm_test_checksum(fpath, pkg->md5sum, ALPM_PKG_VALIDATION_MD5SUM);
|
2008-02-26 18:50:17 -05:00
|
|
|
|
|
|
|
if(retval == 0) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2011-04-20 20:45:16 -04:00
|
|
|
} else if(retval == 1) {
|
2011-07-01 12:01:39 -04:00
|
|
|
pkg->handle->pm_errno = ALPM_ERR_PKG_INVALID;
|
2007-06-03 23:57:38 -04:00
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return retval;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
/* Default package accessor functions. These will get overridden by any
|
|
|
|
* backend logic that needs lazy access, such as the local database through
|
2010-08-02 00:40:04 -04:00
|
|
|
* a lazy-load cache. However, the defaults will work just fine for fully-
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
* populated package structures. */
|
2011-06-28 09:26:39 -04:00
|
|
|
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; }
|
|
|
|
static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; }
|
2011-09-07 11:21:47 -04:00
|
|
|
static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
|
|
|
|
static alpm_time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
|
2011-06-28 09:26:39 -04:00
|
|
|
static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; }
|
|
|
|
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; }
|
|
|
|
static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
|
2011-09-07 11:21:47 -04:00
|
|
|
static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
|
2012-02-18 01:31:37 -05:00
|
|
|
static alpm_pkgvalidation_t _pkg_get_validation(alpm_pkg_t *pkg) { return pkg->validation; }
|
2011-06-28 09:26:39 -04:00
|
|
|
static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; }
|
|
|
|
|
|
|
|
static alpm_list_t *_pkg_get_licenses(alpm_pkg_t *pkg) { return pkg->licenses; }
|
|
|
|
static alpm_list_t *_pkg_get_groups(alpm_pkg_t *pkg) { return pkg->groups; }
|
|
|
|
static alpm_list_t *_pkg_get_depends(alpm_pkg_t *pkg) { return pkg->depends; }
|
|
|
|
static alpm_list_t *_pkg_get_optdepends(alpm_pkg_t *pkg) { return pkg->optdepends; }
|
|
|
|
static alpm_list_t *_pkg_get_conflicts(alpm_pkg_t *pkg) { return pkg->conflicts; }
|
|
|
|
static alpm_list_t *_pkg_get_provides(alpm_pkg_t *pkg) { return pkg->provides; }
|
|
|
|
static alpm_list_t *_pkg_get_replaces(alpm_pkg_t *pkg) { return pkg->replaces; }
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
static alpm_filelist_t *_pkg_get_files(alpm_pkg_t *pkg) { return &(pkg->files); }
|
2011-06-28 09:26:39 -04:00
|
|
|
static alpm_list_t *_pkg_get_backup(alpm_pkg_t *pkg) { return pkg->backup; }
|
|
|
|
|
|
|
|
static void *_pkg_changelog_open(alpm_pkg_t UNUSED *pkg)
|
2011-04-29 07:10:09 -04:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-04 21:07:19 -04:00
|
|
|
static size_t _pkg_changelog_read(void UNUSED *ptr, size_t UNUSED size,
|
2011-09-18 18:07:05 -04:00
|
|
|
const alpm_pkg_t UNUSED *pkg, UNUSED void *fp)
|
2011-04-29 07:10:09 -04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static int _pkg_changelog_close(const alpm_pkg_t UNUSED *pkg,
|
2011-04-29 07:10:09 -04:00
|
|
|
void UNUSED *fp)
|
|
|
|
{
|
|
|
|
return EOF;
|
|
|
|
}
|
2011-04-01 16:13:37 -04:00
|
|
|
|
2011-06-28 23:02:58 -04:00
|
|
|
static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
|
|
|
|
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
/** The standard package operations struct. Get fields directly from the
|
|
|
|
* struct itself with no abstraction layer or any type of lazy loading.
|
|
|
|
*/
|
|
|
|
struct pkg_operations default_pkg_ops = {
|
|
|
|
.get_desc = _pkg_get_desc,
|
|
|
|
.get_url = _pkg_get_url,
|
|
|
|
.get_builddate = _pkg_get_builddate,
|
|
|
|
.get_installdate = _pkg_get_installdate,
|
|
|
|
.get_packager = _pkg_get_packager,
|
|
|
|
.get_arch = _pkg_get_arch,
|
|
|
|
.get_isize = _pkg_get_isize,
|
|
|
|
.get_reason = _pkg_get_reason,
|
2012-02-18 01:31:37 -05:00
|
|
|
.get_validation = _pkg_get_validation,
|
2010-12-13 22:00:23 -05:00
|
|
|
.has_scriptlet = _pkg_has_scriptlet,
|
2011-04-01 16:13:37 -04:00
|
|
|
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
.get_licenses = _pkg_get_licenses,
|
|
|
|
.get_groups = _pkg_get_groups,
|
|
|
|
.get_depends = _pkg_get_depends,
|
|
|
|
.get_optdepends = _pkg_get_optdepends,
|
|
|
|
.get_conflicts = _pkg_get_conflicts,
|
|
|
|
.get_provides = _pkg_get_provides,
|
|
|
|
.get_replaces = _pkg_get_replaces,
|
|
|
|
.get_files = _pkg_get_files,
|
|
|
|
.get_backup = _pkg_get_backup,
|
2011-04-01 16:13:37 -04:00
|
|
|
|
|
|
|
.changelog_open = _pkg_changelog_open,
|
|
|
|
.changelog_read = _pkg_changelog_read,
|
|
|
|
.changelog_close = _pkg_changelog_close,
|
2011-06-28 23:02:58 -04:00
|
|
|
|
|
|
|
.force_load = _pkg_force_load,
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Public functions for getting package information. These functions
|
|
|
|
* delegate the hard work to the function callbacks attached to each
|
|
|
|
* package, which depend on where the package was loaded from. */
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-09-02 23:07:06 -04:00
|
|
|
return pkg->filename;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
|
2005-04-23 13:18:31 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-03-28 13:54:47 -04:00
|
|
|
return pkg->name;
|
2005-04-23 13:18:31 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_version(alpm_pkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-03-28 13:54:47 -04:00
|
|
|
return pkg->version;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-08-29 00:41:17 -04:00
|
|
|
alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg)
|
|
|
|
{
|
|
|
|
ASSERT(pkg != NULL, return -1);
|
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
return pkg->origin;
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg)
|
2007-02-06 12:39:32 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_desc(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2007-02-06 15:57:17 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_url(pkg);
|
2007-02-06 12:39:32 -05:00
|
|
|
}
|
|
|
|
|
2011-09-07 11:21:47 -04:00
|
|
|
alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg)
|
2006-03-08 13:07:58 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_builddate(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-09-07 11:21:47 -04:00
|
|
|
alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_installdate(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_packager(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_packager(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-08-11 21:08:31 -04:00
|
|
|
return pkg->md5sum;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-08-11 21:15:15 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg)
|
|
|
|
{
|
|
|
|
ASSERT(pkg != NULL, return NULL);
|
|
|
|
pkg->handle->pm_errno = 0;
|
2011-08-11 21:08:31 -04:00
|
|
|
return pkg->sha256sum;
|
2011-08-11 21:15:15 -04:00
|
|
|
}
|
|
|
|
|
2011-08-13 14:40:41 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg)
|
|
|
|
{
|
|
|
|
ASSERT(pkg != NULL, return NULL);
|
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
return pkg->base64_sig;
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_arch(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-09-02 23:07:06 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-09-02 20:26:07 -04:00
|
|
|
return pkg->size;
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_isize(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkgreason_t SYMEXPORT alpm_pkg_get_reason(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_reason(pkg);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2006-09-28 16:51:33 -04:00
|
|
|
|
2012-02-18 01:31:37 -05:00
|
|
|
alpm_pkgvalidation_t SYMEXPORT alpm_pkg_get_validation(alpm_pkg_t *pkg)
|
|
|
|
{
|
|
|
|
ASSERT(pkg != NULL, return -1);
|
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
return pkg->ops->get_validation(pkg);
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(alpm_pkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_licenses(pkg);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(alpm_pkg_t *pkg)
|
2008-05-31 09:06:30 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_groups(pkg);
|
2008-05-31 09:06:30 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(alpm_pkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_depends(pkg);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(alpm_pkg_t *pkg)
|
2007-09-26 00:02:30 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_optdepends(pkg);
|
2007-09-26 00:02:30 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(alpm_pkg_t *pkg)
|
2007-02-17 03:55:05 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_conflicts(pkg);
|
2007-02-17 03:55:05 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_provides(alpm_pkg_t *pkg)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_provides(pkg);
|
2006-11-22 04:03:41 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(alpm_pkg_t *pkg)
|
2007-10-19 13:17:51 -04:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_replaces(pkg);
|
2007-10-19 13:17:51 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2011-09-02 23:07:06 -04:00
|
|
|
return pkg->deltas;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_files(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_backup(alpm_pkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least
this commit will get us a heck of a lot closer. The former method of getting
the depends list for a package was the following:
1. call alpm_pkg_get_depends()
2. this method would check if the package came from the cache
3. if so, ensure our cache level is correct, otherwise call db_load
4. finally return the depends list
Why did this suck? Because getting the depends list from the package
shouldn't care about whether the package was loaded from a file, from the
'package cache', or some other system which we can't even use because the
damn thing is so complicated. It should just return the depends list.
So what does this commit change? It adds a pointer to a struct of function
pointers to every package for all of these 'package operations' as I've
decided to call them (I know, sounds completely straightforward, right?). So
now when we call an alpm_pkg_get-* function, we don't do any of the cache
logic or anything else there- we let the actual backend handle it by
delegating all work to the method at pkg->ops->get_depends.
Now that be_package has achieved equal status with be_files, we can treat
packages from these completely different load points differently. We know a
package loaded from a zip file will have all of its fields populated, so
we can set up all its accessor functions to be direct accessors. On the
other hand, the packages loaded from the local and sync DBs are not always
fully-loaded, so their accessor functions are routed through the same logic
as before.
Net result? More code. However, this code now make it roughly 52 times
easier to open the door to something like a read-only tar.gz database
backend.
Are you still reading? I'm impressed. Looking at the patch will probably be
clearer than this long-winded explanation.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Allan: rebase and adjust]
Signed-off-by: Allan McRae <allan@archlinux.org>
2008-05-11 17:00:33 -04:00
|
|
|
return pkg->ops->get_backup(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg)
|
2008-08-17 12:32:39 -04:00
|
|
|
{
|
|
|
|
/* Sanity checks */
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
|
|
|
ASSERT(pkg->origin != PKG_FROM_FILE, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2008-08-17 12:32:39 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg->origin_data.db;
|
2008-08-17 12:32:39 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Open a package changelog for reading. */
|
2011-06-28 09:26:39 -04:00
|
|
|
void SYMEXPORT *alpm_pkg_changelog_open(alpm_pkg_t *pkg)
|
2007-12-09 00:42:04 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2008-05-11 17:49:01 -04:00
|
|
|
return pkg->ops->changelog_open(pkg);
|
2007-12-09 00:42:04 -05:00
|
|
|
}
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Read data from an open changelog 'file stream'. */
|
2007-12-09 00:42:04 -05:00
|
|
|
size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size,
|
2011-09-18 18:07:05 -04:00
|
|
|
const alpm_pkg_t *pkg, void *fp)
|
2007-12-09 00:42:04 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return 0);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2008-05-11 17:49:01 -04:00
|
|
|
return pkg->ops->changelog_read(ptr, size, pkg, fp);
|
2007-12-09 00:42:04 -05:00
|
|
|
}
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Close a package changelog for reading. */
|
2011-06-28 09:26:39 -04:00
|
|
|
int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp)
|
2007-12-09 00:42:04 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2008-05-11 17:49:01 -04:00
|
|
|
return pkg->ops->changelog_close(pkg, fp);
|
2007-12-09 00:42:04 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
2010-12-13 22:00:23 -05:00
|
|
|
return pkg->ops->has_scriptlet(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs)
|
2009-10-07 22:52:09 -04:00
|
|
|
{
|
|
|
|
const alpm_list_t *i;
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
|
2011-02-25 09:22:09 -05:00
|
|
|
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *cachepkg = i->data;
|
2011-06-27 11:10:08 -04:00
|
|
|
alpm_list_t *j;
|
|
|
|
for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) {
|
|
|
|
if(_alpm_depcmp(pkg, j->data)) {
|
2011-03-25 16:34:39 -04:00
|
|
|
const char *cachepkgname = cachepkg->name;
|
|
|
|
if(alpm_list_find_str(*reqs, cachepkgname) == NULL) {
|
|
|
|
*reqs = alpm_list_add(*reqs, strdup(cachepkgname));
|
|
|
|
}
|
2010-03-24 01:59:04 -04:00
|
|
|
}
|
2009-10-07 22:52:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-06 13:07:25 -05:00
|
|
|
/** Compute the packages requiring a given package. */
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg)
|
2007-08-25 19:07:02 -04:00
|
|
|
{
|
2008-07-01 16:53:13 -04:00
|
|
|
const alpm_list_t *i;
|
2007-08-25 19:07:02 -04:00
|
|
|
alpm_list_t *reqs = NULL;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db;
|
2009-10-07 22:52:09 -04:00
|
|
|
|
2011-06-14 11:09:35 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
|
2009-10-07 22:52:09 -04:00
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
/* The sane option; search locally for things that require this. */
|
2011-06-09 16:23:24 -04:00
|
|
|
find_requiredby(pkg, pkg->handle->db_local, &reqs);
|
2009-10-07 22:52:09 -04:00
|
|
|
} else {
|
|
|
|
/* We have a DB package. if it is a local package, then we should
|
|
|
|
* only search the local DB; else search all known sync databases. */
|
|
|
|
db = pkg->origin_data.db;
|
2011-08-17 22:06:04 -04:00
|
|
|
if(db->status & DB_STATUS_LOCAL) {
|
2009-10-07 22:52:09 -04:00
|
|
|
find_requiredby(pkg, db, &reqs);
|
|
|
|
} else {
|
2011-06-03 13:44:01 -04:00
|
|
|
for(i = pkg->handle->dbs_sync; i; i = i->next) {
|
2009-10-07 22:52:09 -04:00
|
|
|
db = i->data;
|
|
|
|
find_requiredby(pkg, db, &reqs);
|
|
|
|
}
|
2011-03-25 16:34:39 -04:00
|
|
|
reqs = alpm_list_msort(reqs, alpm_list_count(reqs), _alpm_str_cmp);
|
2007-08-25 19:07:02 -04:00
|
|
|
}
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return reqs;
|
2007-08-25 19:07:02 -04:00
|
|
|
}
|
|
|
|
|
2008-05-30 00:12:44 -04:00
|
|
|
/** @} */
|
2007-07-18 10:26:21 -04:00
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_file_t *_alpm_file_copy(alpm_file_t *dest,
|
|
|
|
const alpm_file_t *src)
|
2011-06-16 14:16:49 -04:00
|
|
|
{
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
STRDUP(dest->name, src->name, return NULL);
|
|
|
|
dest->size = src->size;
|
|
|
|
dest->mode = src->mode;
|
2011-06-16 14:16:49 -04:00
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
return dest;
|
2011-06-16 14:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function for comparing files list entries
|
|
|
|
*/
|
|
|
|
int _alpm_files_cmp(const void *f1, const void *f2)
|
|
|
|
{
|
|
|
|
const alpm_file_t *file1 = f1;
|
|
|
|
const alpm_file_t *file2 = f2;
|
|
|
|
return strcmp(file1->name, file2->name);
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *_alpm_pkg_new(void)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t* pkg;
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
CALLOC(pkg, 1, sizeof(alpm_pkg_t), return NULL);
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-11-30 22:04:16 -05:00
|
|
|
static alpm_list_t *list_depdup(alpm_list_t *old)
|
|
|
|
{
|
|
|
|
alpm_list_t *i, *new = NULL;
|
|
|
|
for(i = old; i; i = i->next) {
|
|
|
|
new = alpm_list_add(new, _alpm_dep_dup(i->data));
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2011-08-19 12:06:55 -04:00
|
|
|
/**
|
|
|
|
* Duplicate a package data struct.
|
|
|
|
* @param pkg the package to duplicate
|
|
|
|
* @param new_ptr location to store duplicated package pointer
|
|
|
|
* @return 0 on success, -1 on fatal error, 1 on non-fatal error
|
|
|
|
*/
|
|
|
|
int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *newpkg;
|
2008-01-11 02:00:15 -05:00
|
|
|
alpm_list_t *i;
|
2011-08-19 12:06:55 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if(!pkg || !pkg->handle) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!new_ptr) {
|
|
|
|
RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1);
|
|
|
|
}
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2011-06-28 23:02:58 -04:00
|
|
|
if(pkg->ops->force_load(pkg)) {
|
2011-08-19 12:06:55 -04:00
|
|
|
_alpm_log(pkg->handle, ALPM_LOG_WARNING,
|
|
|
|
_("could not fully load metadata for package %s-%s\n"),
|
|
|
|
pkg->name, pkg->version);
|
|
|
|
ret = 1;
|
|
|
|
pkg->handle->pm_errno = ALPM_ERR_PKG_INVALID;
|
2011-06-28 23:02:58 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
CALLOC(newpkg, 1, sizeof(alpm_pkg_t), goto cleanup);
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2010-12-14 13:06:31 -05:00
|
|
|
newpkg->name_hash = pkg->name_hash;
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->filename, pkg->filename, goto cleanup);
|
|
|
|
STRDUP(newpkg->name, pkg->name, goto cleanup);
|
|
|
|
STRDUP(newpkg->version, pkg->version, goto cleanup);
|
|
|
|
STRDUP(newpkg->desc, pkg->desc, goto cleanup);
|
|
|
|
STRDUP(newpkg->url, pkg->url, goto cleanup);
|
2008-01-11 01:01:58 -05:00
|
|
|
newpkg->builddate = pkg->builddate;
|
|
|
|
newpkg->installdate = pkg->installdate;
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->packager, pkg->packager, goto cleanup);
|
|
|
|
STRDUP(newpkg->md5sum, pkg->md5sum, goto cleanup);
|
2011-08-11 21:15:15 -04:00
|
|
|
STRDUP(newpkg->sha256sum, pkg->md5sum, goto cleanup);
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newpkg->arch, pkg->arch, goto cleanup);
|
2008-01-11 01:01:58 -05:00
|
|
|
newpkg->size = pkg->size;
|
|
|
|
newpkg->isize = pkg->isize;
|
|
|
|
newpkg->scriptlet = pkg->scriptlet;
|
|
|
|
newpkg->reason = pkg->reason;
|
|
|
|
|
2008-07-24 20:02:17 -04:00
|
|
|
newpkg->licenses = alpm_list_strdup(pkg->licenses);
|
2011-11-30 22:04:16 -05:00
|
|
|
newpkg->replaces = list_depdup(pkg->replaces);
|
2008-07-24 20:02:17 -04:00
|
|
|
newpkg->groups = alpm_list_strdup(pkg->groups);
|
2011-11-30 22:04:16 -05:00
|
|
|
for(i = pkg->backup; i; i = i->next) {
|
|
|
|
newpkg->backup = alpm_list_add(newpkg->backup, _alpm_backup_dup(i->data));
|
|
|
|
}
|
|
|
|
newpkg->depends = list_depdup(pkg->depends);
|
2011-07-17 19:54:06 -04:00
|
|
|
newpkg->optdepends = list_depdup(pkg->optdepends);
|
2011-11-30 22:04:16 -05:00
|
|
|
newpkg->conflicts = list_depdup(pkg->conflicts);
|
|
|
|
newpkg->provides = list_depdup(pkg->provides);
|
|
|
|
for(i = pkg->deltas; i; i = i->next) {
|
|
|
|
newpkg->deltas = alpm_list_add(newpkg->deltas, _alpm_delta_dup(i->data));
|
|
|
|
}
|
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
if(pkg->files.count) {
|
|
|
|
size_t filenum;
|
|
|
|
size_t len = sizeof(alpm_file_t) * pkg->files.count;
|
|
|
|
MALLOC(newpkg->files.files, len, goto cleanup);
|
|
|
|
for(filenum = 0; filenum < pkg->files.count; filenum++) {
|
|
|
|
if(!_alpm_file_copy(newpkg->files.files + filenum,
|
|
|
|
pkg->files.files + filenum)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newpkg->files.count = pkg->files.count;
|
2011-06-16 14:16:49 -04:00
|
|
|
}
|
2008-01-11 01:01:58 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* internal */
|
2011-06-03 13:13:22 -04:00
|
|
|
newpkg->infolevel = pkg->infolevel;
|
2008-01-11 01:01:58 -05:00
|
|
|
newpkg->origin = pkg->origin;
|
2007-08-14 10:14:35 -04:00
|
|
|
if(newpkg->origin == PKG_FROM_FILE) {
|
|
|
|
newpkg->origin_data.file = strdup(pkg->origin_data.file);
|
|
|
|
} else {
|
|
|
|
newpkg->origin_data.db = pkg->origin_data.db;
|
|
|
|
}
|
2011-06-03 13:13:22 -04:00
|
|
|
newpkg->ops = pkg->ops;
|
2011-06-03 13:44:01 -04:00
|
|
|
newpkg->handle = pkg->handle;
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2011-08-19 12:06:55 -04:00
|
|
|
*new_ptr = newpkg;
|
|
|
|
return ret;
|
2011-06-07 17:06:16 -04:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
_alpm_pkg_free(newpkg);
|
2011-08-19 12:06:55 -04:00
|
|
|
RET_ERR(pkg->handle, ALPM_ERR_MEMORY, -1);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2011-11-30 22:04:16 -05:00
|
|
|
static void free_deplist(alpm_list_t *deps)
|
|
|
|
{
|
|
|
|
alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_dep_free);
|
|
|
|
alpm_list_free(deps);
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
void _alpm_pkg_free(alpm_pkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(pkg->filename);
|
|
|
|
FREE(pkg->name);
|
|
|
|
FREE(pkg->version);
|
|
|
|
FREE(pkg->desc);
|
|
|
|
FREE(pkg->url);
|
|
|
|
FREE(pkg->packager);
|
|
|
|
FREE(pkg->md5sum);
|
2011-08-11 21:15:15 -04:00
|
|
|
FREE(pkg->sha256sum);
|
2011-04-21 20:25:44 -04:00
|
|
|
FREE(pkg->base64_sig);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(pkg->arch);
|
2011-08-09 02:00:16 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
FREELIST(pkg->licenses);
|
2011-11-30 22:04:16 -05:00
|
|
|
free_deplist(pkg->replaces);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREELIST(pkg->groups);
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
if(pkg->files.count) {
|
|
|
|
size_t i;
|
|
|
|
for(i = 0; i < pkg->files.count; i++) {
|
|
|
|
free(pkg->files.files[i].name);
|
|
|
|
}
|
|
|
|
free(pkg->files.files);
|
|
|
|
}
|
2011-06-16 14:15:11 -04:00
|
|
|
alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free);
|
|
|
|
alpm_list_free(pkg->backup);
|
2011-11-30 22:04:16 -05:00
|
|
|
free_deplist(pkg->depends);
|
2011-07-17 19:54:06 -04:00
|
|
|
free_deplist(pkg->optdepends);
|
2011-11-30 22:04:16 -05:00
|
|
|
free_deplist(pkg->conflicts);
|
|
|
|
free_deplist(pkg->provides);
|
2008-01-12 02:27:02 -05:00
|
|
|
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
|
|
|
|
alpm_list_free(pkg->deltas);
|
2008-02-16 11:47:22 -05:00
|
|
|
alpm_list_free(pkg->delta_path);
|
2009-03-07 13:44:34 -05:00
|
|
|
alpm_list_free(pkg->removes);
|
2008-01-11 01:01:58 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
2007-08-14 10:14:35 -04:00
|
|
|
FREE(pkg->origin_data.file);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
FREE(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
/* This function should be used when removing a target from upgrade/sync target list
|
|
|
|
* Case 1: If pkg is a loaded package file (PKG_FROM_FILE), it will be freed.
|
|
|
|
* Case 2: If pkg is a pkgcache entry (PKG_FROM_CACHE), it won't be freed,
|
|
|
|
* only the transaction specific fields of pkg will be freed.
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
void _alpm_pkg_free_trans(alpm_pkg_t *pkg)
|
2009-06-07 08:30:11 -04:00
|
|
|
{
|
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
_alpm_pkg_free(pkg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-07 08:30:11 -04:00
|
|
|
alpm_list_free(pkg->removes);
|
|
|
|
pkg->removes = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-08 09:39:23 -04:00
|
|
|
/* Is spkg an upgrade for localpkg? */
|
2011-06-28 09:26:39 -04:00
|
|
|
int _alpm_pkg_compare_versions(alpm_pkg_t *spkg, alpm_pkg_t *localpkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-08-18 00:25:19 -04:00
|
|
|
return alpm_pkg_vercmp(spkg->version, localpkg->version);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Helper function for comparing packages
|
|
|
|
*/
|
|
|
|
int _alpm_pkg_cmp(const void *p1, const void *p2)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2011-06-16 14:16:49 -04:00
|
|
|
const alpm_pkg_t *pkg1 = p1;
|
|
|
|
const alpm_pkg_t *pkg2 = p2;
|
2011-09-27 21:24:04 -04:00
|
|
|
return strcmp(pkg1->name, pkg2->name);
|
2007-11-18 13:05:47 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Test for existence of a package in a alpm_list_t*
|
2011-06-28 09:26:39 -04:00
|
|
|
* of alpm_pkg_t*
|
2007-07-18 10:26:21 -04:00
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t *lp;
|
2010-12-14 13:36:02 -05:00
|
|
|
unsigned long needle_hash;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(needle == NULL || haystack == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2010-12-14 13:36:02 -05:00
|
|
|
needle_hash = _alpm_hash_sdbm(needle);
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
for(lp = haystack; lp; lp = lp->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *info = lp->data;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2010-12-14 13:36:02 -05:00
|
|
|
if(info) {
|
2011-08-09 00:57:19 -04:00
|
|
|
if(info->name_hash != needle_hash) {
|
2010-12-14 13:36:02 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finally: we had hash match, verify string match */
|
|
|
|
if(strcmp(info->name, needle) == 0) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return info;
|
2010-12-14 13:36:02 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:13:29 -05:00
|
|
|
/** Test if a package should be ignored.
|
|
|
|
*
|
|
|
|
* Checks if the package is ignored via IgnorePkg, or if the package is
|
2011-06-29 01:59:48 -04:00
|
|
|
* in a group ignored via IgnoreGroup.
|
2007-11-09 20:13:29 -05:00
|
|
|
*
|
2011-06-09 16:18:47 -04:00
|
|
|
* @param handle the context handle
|
2007-11-09 20:13:29 -05:00
|
|
|
* @param pkg the package to test
|
|
|
|
*
|
|
|
|
* @return 1 if the package should be ignored, 0 otherwise
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
int _alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg)
|
2007-11-09 20:13:29 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *groups = NULL;
|
|
|
|
|
|
|
|
/* first see if the package is ignored */
|
2011-10-30 13:33:14 -04:00
|
|
|
if(alpm_list_find(handle->ignorepkg, pkg->name, _alpm_fnmatch)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-11-09 20:13:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* next see if the package is in a group that is ignored */
|
2011-11-11 15:56:18 -05:00
|
|
|
for(groups = alpm_pkg_get_groups(pkg); groups; groups = groups->next) {
|
2011-09-19 15:32:53 -04:00
|
|
|
char *grp = groups->data;
|
2011-10-30 13:33:14 -04:00
|
|
|
if(alpm_list_find(handle->ignoregroup, grp, _alpm_fnmatch)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-11-09 20:13:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-11-09 20:13:29 -05:00
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|