summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_local.c
AgeCommit message (Collapse)AuthorFilesLines
2016-10-22Represent bitfields as ints, not enumsIvy Foster1-4/+4
Many bitfield variables are declared to be enums, because they are generated using bitwise operations on enums such. However, their actual values aren't necessary members of their parent enum, so declaring them 'int' is more accurate. Signed-off-by: Ivy Foster <ivy.foster@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2016-09-25Return boolean from db_populateRikard Falkeborn1-1/+1
Since the number of packages is not used anywhere, just return a boolean to avoid the implicit cast from size_t to int in be_local.c. Use 0 as success to be consistent with db_validate. Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2016-09-20Fix gcc strict-overflow errorRikard Falkeborn1-3/+3
Recent gcc (tested with 6.2.1) produces the following error when compiling with both --enable-warningflags and --enable-debug. In particular, it seems it is the combination of GCC_STACK_PROTECT_LIB and -Wstrict-overflow=5 produces the error. be_local.c:609:4: error: assuming signed overflow does not occur when simplifying conditional [-Werror=strict-overflow] if(count > 0) { Fix this by changing the type of count from int to size_t, which is fine since count is never negative. Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2016-08-30Release resources on error paths.Tobias Stoeckmann1-3/+16
Some resources (memory or file descriptors) are not released on all error paths. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2016-01-04Update copyright years for 2016Allan McRae1-1/+1
make update-copyright OLD=2015 NEW=2016 Signed-off-by: Allan McRae <allan@archlinux.org>
2015-11-03ensure realloc has a positive sizeAndrew Gregory1-3/+7
If given size 0 POSIX allows realloc to return a pointer that is not suitable for use. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2015-03-03Abort of failure to add version file to empty local databaseAllan McRae1-2/+12
Signed-off-by: Allan McRae <allan@archlinux.org>
2015-02-01Update copyright notices for 2015Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2015-01-21Merge branch 'maint'Allan McRae1-1/+1
2015-01-21be_local: fix _alpm_greedy_grow usageDaniel Micay1-1/+1
The files_size variable contains the current capacity (in bytes) and should not be used to calculate the next length increment. It only works because _alpm_greedy_grow currently results in incremental growth. Signed-off-by: Daniel Micay <danielmicay@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-12-27Remove logically dead code in _alpm_local_db_writeAllan McRae1-5/+0
We can only get to cleanup: through fp being NULL due to fopen failing or normal execution when fclose is called. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-12-24libalpm: Add accessors for the base fieldJohannes Löthberg1-0/+7
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-12-24libalpm: Parse and write PKGBASEsJohannes Löthberg1-0/+6
This commit adds support to libalpm to parse the pkgbase present in packages .PKGINFO files, writing the PKGBASE to the %BASE% section of the local DBs desc files and for parsing it again when loading the local DB Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-12-24local_db_read: fix memory leak on errorAllan McRae1-0/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-09-30libalpm: export alpm_splitdep as alpm_dep_from_depstring and alpm_dep_freeFlorian Pritz1-1/+1
Signed-off-by: Florian Pritz <bluewind@xinu.at>
2014-09-23wrap fgets to retry on EINTRAndrew Gregory1-7/+7
The read() underlying fgets() can be interrupted by a signal handler causing fgets() to return NULL. Before we started handling SIGWINCH, the odds of interrupting a read were low and typically resulted in termination anyway. Replace all fgets calls with a wrapper that retries in EINTR. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-09-23Check the version of the local database during validationAllan McRae1-18/+11
When we check the database version directly, there is no longer a need to scan for depends files. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-09-23Add version file to empty local databaseAllan McRae1-12/+32
If a user manually creates the local database directory, or has an empty local database for some other reason, we silently add a version file Signed-off-by: Allan McRae <allan@archlinux.org>
2014-09-23Add version file when creating local database directoryAllan McRae1-0/+18
The version of the local pacman database is stored in its root in the file ALPM_DB_VERSION. The version is starting at 9, corresponding to the next libalpm library version. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-09-23Create local database directory if it is missingAllan McRae1-14/+26
This means that a missing local database becomes an error (as it should be immediately created). Note this only creates the "local" directory and not its parent, which is checked for during locking. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-08Use MALLOC throughtout libalpmAllan McRae1-5/+1
Use MALLOC instead of malloc for safety in libalpm. Some changes are pure refactoring, but for others this provides a success check for memory allocation. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-03be_local: Use alpm_greedy_growFlorian Pritz1-16/+3
Signed-off-by: Florian Pritz <bluewind@xinu.at>
2014-01-30local_db_populate: initialize empty pkgcacheAndrew Gregory1-0/+1
If the db directory did not exist when local_db_populate was called, the pkgcache wouldn't be initialized, causing pkghash_add_pkg to fail. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-28Remove ts and sw from vim modeline when noet is setFlorian Pritz1-1/+1
Forcing vim users to view files with a tabstop of 2 seems really unnecessary when noet is set. I find it much easier to read code with ts=4 and I dislike having to override the modeline by hand. Command run: find . -type f -exec sed -i '/vim.* noet/s# ts=2 sw=2##' {} + Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06Update copyright years for 2014Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06Update comment for local db entry creationAllan McRae1-2/+2
Mention mtree files do not need creation in addtion to install files. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-09-04libalpm: introduce a usage level for reposDave Reisner1-0/+1
This defines a level of interest a user has in a repository. These are described by the bitmask flags in the alpm_db_usage_t enum: ALPM_DB_USAGE_SEARCH: repo is valid for searching ALPM_DB_USAGE_INSTALL: repo is valid for installs (e.g. -S pkg) ALPM_DB_USAGE_UPGRADE: repo is valid for sysupgrades ALPM_DB_USAGE_ALL: all of the above are valid Explicitly listing the contents of a repo will always be valid, and the repo will always be refreshed appropriately on sync operations. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-29Restore libarchive 2.8.x compatibilityDan McGee1-1/+1
We still call some of these 'deprecated' methods elsewhere, so this shouldn't present a problem. When we decide 2.x support is to be dropped, we should update all of the code to not call deprecated methods. Allan: Adjusted with respect to previous patches adding libarchive compatibilty layer. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-29Use libarchive compat header for relevant symbolsDave Reisner1-3/+4
Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-03Update copyright year for 2013Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14Add public functions for accessing mtree dataAllan McRae1-2/+0
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14Add internal functions for reading mtree file from local dbAllan McRae1-0/+77
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14Plug various minor memory leaksAndrew Gregory1-0/+1
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2012-08-02Move filelist functions into separate source fileDan McGee1-0/+1
We have a few of these and might as well gather them together. This also cleans up the code a bit by using an enum instead of integer values, as well as makes a "search for file in filelist" function public so frontends can do better than straight linear search of the filelists. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-08-01lib/be_local: ensure local filelists are sortedDave Reisner1-0/+2
This may very well be a no-op, but better safe than sorry. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-06-26add line length parameter to _alpm_strip_newlineDave Reisner1-7/+7
If known, callers can pass the line size to this function in order to avoid an strlen call. Otherwise, they simply pass 0 and _alpm_strip_newline will do the call instead. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-30Convert ALLOC_FAIL macro into a functionDan McGee1-2/+2
This path is rarely (read: never) taken in any normal run of the code, so injecting the fprintf() call everywhere with the macro is a bit overkill. Instead, add a lightweight _alpm_alloc_fail() function that gets called instead. This does have a reasonable effect on the size of the generated code; most places using the macros provided by util.c have their code size reduced. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-30be_local: use the right length value for filename in all casesDan McGee1-2/+3
Increment the strlen() provided value by 1 for the NULL byte so we use the right value in all three places we later reference it. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-25be_local: write all single-valued attributes firstDan McGee1-18/+20
There isn't a whole lot of reason other than code clarity for this, but it makes it a bit more obvious where multivalued attributes start. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-07Prefix alpm_pkgfrom_t members with ALPM_Allan McRae1-2/+2
Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Prefer fputs/fputc over fprintf when writing local databaseDan McGee1-11/+15
Using fputs should be faster as no format string parsing is required. It also prevents silly errors related to unescaped '%' signs, and removes the need to double them up in a lot of places. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Extract a write_deps function from local database writingDan McGee1-45/+22
This reduces a lot of code duplication in the write function, which cleans it up a bit. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Remove unnecessary path check from local databaseDan McGee1-12/+3
This removes a call to _alpm_local_db_pkgpath() as well as an access() call when reading the local database. This appears to be code from 2006 that has stuck around. We don't need it because: 1) We never use this path except to check it via access(); however, we are already in a readdir() loop so it exists, or at least did at the time of the call. 2) The fopen() and other calls will fail on accessing the database files anyway, and we need to check those for errors. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-09Add information on how an installed package was validatedAllan McRae1-0/+43
When installing a package, store information on which validation method was used and output this on "pacman -Qi" operations. e.g. Validated By : SHA256 Sum Possible values are Unknown, None, MD5 Sum, SHA256 Sum, Signature. Dan: just a few very minor tweaks. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-09Hook new optdepend structures upBenedikt Morbach1-2/+4
No new behaviour introduced, everything should work exactly as before. Dan: refactored to use the single alpm_depend_t structure. Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-20Update copyright yearsAllan McRae1-1/+1
Add 2012 to the copyright range for all libalpm and pacman source files. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-06ALPM API adjustments for sanity and consistencyDan McGee1-0/+24
This makes several small adjustments to our exposed method names, and in one case, parameters. The justification here is to make methods less odd in their naming convention. If a method takes an alpm_db_t argument, the method should be named 'alpm_db_*', but perhaps more importantly, if it doesn't take a database as the first parameter, it should not. Summary of changes: alpm_db_register_sync -> alpm_register_syncdb alpm_db_unregister_all -> alpm_unregister_all_syncdbs alpm_option_get_localdb -> aplpm_get_localdb alpm_option_get_syncdbs -> aplpm_get_syncdbs alpm_db_readgroup -> alpm_db_get_group alpm_db_set_pkgreason -> alpm_pkg_set_reason All methods keep the same argument list except for alpm_pkg_set_reason; there we drop the 'handle' argument as it can be retrieved from the passed in package object. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-23Remove rmrf implementation from backendDan McGee1-5/+35
This moves the code for removal of local database entries right into be_local.c, which was the last user of the rmrf() function we had in our utility source file. We can simplify the implementation and make it non-recursive as we know the structure of the local database entries. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-03pkghash improvements/modificationsDan McGee1-2/+1
This patch changes a variety of small things related to our pkghash implementation with an eye toward performance, especially on native 32-bit systems. * Use `unsigned int` rather than `size_t` for hash sizes. We already return ERANGE for any attempted creation of a hash greater than 1 million elements, so unsigned int is more than large enough for our purposes. Switching to this type allows 32 bit systems to do native math without helper functions from libgcc. * _alpm_pkghash_create() now internally adds extra padding for additional array elements, rather than that being the responsibility of the caller. * #define values are moved into static const values in pkghash.c; a new `stride` value is also extracted (but remains set at 1). * Division and modulus operators are removed from the normal find and add paths if possible. We store the upper limit of the number of elements in the hash so we no longer need to calculate this every element addition. When doing wraparound position calculations, we only apply the modulus operator if the value is greater than the number of buckets. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-22include config.h via MakefilesDave Reisner1-2/+0
Ensures that config.h is always ordered correctly (first) in the includes. Also means that new source files get this for free without having to remember to add it. We opt for -imacros over -include as its more portable, and the added constraint by -imacros doesn't bother us for config.h. This also touches the HACKING file to remove the explicit mention of config.h as part of the includes. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>