summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.h
AgeCommit message (Collapse)AuthorFilesLines
2017-01-04Update copyright yearsAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2016-10-22Represent bitfields as ints, not enumsIvy Foster1-1/+2
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-25Do not #define _RESERVED_IDENTIFIERSIvy Foster1-3/+3
Signed-off-by: Ivy Foster <ivy.foster@gmail.com> 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-09-20move strtrim to util-commonAndrew Gregory1-1/+0
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2015-07-15pacman: move database syncing to util.cAllan McRae1-0/+1
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>
2014-06-29cache terminal size, add SIGWINCH handler to resetDave Reisner1-1/+2
Refactoring getcols, yet again. We do the following: 1) Introduce a static global in src/pacman/util.c 2) getcols always prefers this cached value, but will derive it from the COLUMNS environment var, the characteristics of stdout, or a sane default (in that order). 3) Introduce a SIGWINCH signal handler to reset the cached value, meaning we only call ioctl when we don't know the value. On my machine, pacman -Syy goes from ~4300 ioctl calls to 3.
2014-03-03Add events on pacnew/pacsave/pacorig file creationOlivier Brunel1-0/+1
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Note that there are 2 cases for installing a .pacnew file, to not overwrite user changes and because file is in NoUpgrade. In the later case the warning was a bit different: it happened before and said "extracting" instead of "installed." Now both happen after and are phrased the same. Signed-off-by: Olivier Brunel <jjk@jjacky.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-06Fix build warnings with --disable-nlsAllan McRae1-2/+2
The gettext functions return a "char *", so do the same for the defines in the case where gettext is unavailable. This prevents a number of warnings about const being dropped. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-10-14pacman/util: remove strsplitAndrew Gregory1-1/+0
strsplit was used in only one place and did the same thing as strtok. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07standardize format functionsSimon Gomizelj1-3/+3
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07remove :: prefix from all messageSimon Gomizelj1-0/+1
This will substantially simplify the logic to add colours to messages. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-02-13Add format attributes to all required functionsAllan McRae1-3/+3
Fixes all clang warnings with -Wformat-literal. Also, fix genuine formating issue discovered once adding these attributes and add a cast to prevent a gcc warning. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Split common utility functions for libalpm and pacmanAllan McRae1-6/+2
There is duplicated code in the util.c files in the libalpm and pacman source code. Split this into a separate file so that it can be shared via a symlink. This prevents code divergence between the two code bases. Also, move mbasename and mdirname from pacman/util.c into util-common.c in preparation for the following patch that uses them to add an extension to pacsave files. 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-03-17Change table_display() to be staticDan McGee1-2/+0
It is only used inside util.c. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Reduce calls to getcolsDan McGee1-6/+10
This dramatically improves upon a much older attempt in 2008 in commit ce3d70aa99ab86. We don't need to call it once per line we print unless there is a reasonable expectation of being able to resize the terminal mid-operation; this is really only the case during our callback progress bars. Some before and after numbers of ioctl() calls, gleaned from strace of the following operations (no targets to any of them to maximize the amount of output): pacman -Qii : 37768 -> 2616 (93.1% decrease) pacman -Qs : 2616 -> 4 (99.8%) pacman -Sii : 133036 -> 10926 (91.8%) pacman -Ss : 10926 -> 14 (99.9%) Obviously the search results are astounding; we only call getcols() once in the case of -Qs, and once per repo in the case of -Ss. For -Qii and -Sii we are still calling it once per package, but this is much better than once per line of info output. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Pass a file descriptor to getcols and flush_term_inputDan McGee1-1/+1
This makes these methods a bit more flexible. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-06Merge branch 'maint'Dan McGee1-1/+2
Conflicts: lib/libalpm/alpm_list.c
2012-02-03Fix FS#27924: don't display negative zeroesThomas Dziedzic1-1/+2
Dan: don't compute lower bound unless needed, flip argument order so out values are last, add param Doxygen documentation. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-23Merge branch 'maint'Dan McGee1-2/+1
Conflicts: lib/libalpm/diskspace.c src/pacman/util.h
2012-01-19Update copyright on changed files since beginning of yearDan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-18Remove unused strtoupper() functionDan McGee1-1/+0
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-02Convert get_update_timediff to integer return valueDan McGee1-3/+0
We don't need absolute floating point precision at all here; we can stick to integer land and use milliseconds which are precise enough for our purposes. This also removes most floating point math out of the non-update code path. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-23pacman/util: return size_t from strtrimDave Reisner1-1/+1
Instead of returning the same value as the parameter to this function, return the length of the string, which can be useful to the caller when its non-zero (e.g. to find the end of the string). Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-10-21Remove pm_fprintf() in favor of pm_printf()Dan McGee1-1/+1
Now that pm_printf() always prints to stderr, we don't need this second function that was always used with stderr as the first argument. Thus, this patch removes the function and makes the following sed replacement: sed -i -e 's#pm_fprintf(stderr, #pm_printf(#g' src/pacman/*.c Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Use unsigned types for indent width and column countDan McGee1-2/+2
For getcols(), the functions we call return a value of type 'unsigned short', so it makes sense for us to do the same. string_length() is meant to behave like strlen(), so it should return type size_t. This exposes other functions such as indentprint() which should also be using signed return types. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Keep track of explicitly added and removed packagesDan McGee1-0/+1
This allows us to sort the output list by showing all pulled dependencies first, followed by the explicitly specified targets. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Combine add and removal package list displayDan McGee1-1/+6
There was no real reason for these to be done separately. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-30Improve advice for sync ops when db.lck is presentPang Yan Han1-0/+1
When the database is locked, sync operations involving transactions, such as pacman -Syy, show the following: :: Synchronizing package databases... error: failed to update core (unable to lock database) error: failed to update extra (unable to lock database) error: failed to update community (unable to lock database) error: failed to update multilib (unable to lock database) error: failed to synchronize any databases Whereas pacman -U <pkg> shows: error: failed to init transaction (unable to lock database) if you're sure a package manager is not already running, you can remove /var/lib/pacman/db.lck Which is much more meaningful, since the presence of db.lck may indicate an erroneous lockfile instead of an ongoing transaction. Improve the error messages for sync operations by advising the user to remove db.lck if he is sure that no package manager is running. Signed-off-by: Pang Yan Han <pangyanhan@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-29Refactor signature result return formatDan McGee1-1/+1
I was trying to take a shortcut and not introduce a wrapper struct for the signature results, so packed it all into alpm_sigresult_t in the first iteration. However, this is painful when one wants to add new fields or only return information regarding a single signature. Refactor the type into a few components which are exposed to the end user, and will allow a lot more future flexibility. This also exposes more information regarding the key to the frontend than was previously available. The "private" void *data pointer is used by the library to store the actual key object returned by gpgme; it is typed this way so the frontend has no expectations of what is there, and so we don't have any hard gpgme requirement in our public API. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-25Remove short/long label distinctionDan McGee1-1/+1
We only used short labels in one place, and the short label is always the first character of the long label anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-05Allow invalid sync DBs to be returned by the libraryDan McGee1-1/+2
They are placeholders, but important for things like trying to re-sync a database missing a signature. By using the alpm_db_validity() method at the right time, a client can take the appropriate action with these invalid databases as necessary. In pacman's case, we disallow just about anything that involves looking at a sync database outside of an '-Sy' operation (although we do check the validity immediately after). A few operations are still permitted- '-Q' ops that don't touch sync databases as well as '-R'. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-05Allow frontend access to signature verification informationDan McGee1-0/+1
Show output in -Qip for each package signature, which includes the UID string from the key ("Joe User <joe@example.com>") and the validity of said key. Example output: Signatures : Valid signature from "Dan McGee <dpmcgee@gmail.com>" Unknown signature from "<Key Unknown>" Invalid signature from "Dan McGee <dpmcgee@gmail.com>" Also add a backend alpm_sigresult_cleanup() function since memory allocation took place on this object, and we need some way of freeing it. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-28Rename pmtransflag_t to alpm_transflag_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmloglevel_t to alpm_loglevel_tAllan McRae1-4/+4
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmpkg_t to alpm_pkg_tAllan McRae1-2/+2
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-20pacman/util.c: support terminals with unknown widthDave Reisner1-1/+1
Add detection for stdout being attached to a tty device. When this check fails, return a default width of 0, which callers interpret to mean "don't wrap". Conversely, when our term ioctl suceeds but returns 0, we interpret this to mean a tty with an unknown width (e.g., a serial console), in which case we default to a sane value of 80. Signed-off-by: Dave Reisner <d@falconindy.com>
2011-06-03Merge branch 'maint'Dan McGee1-1/+1
Conflicts: src/pacman/callback.c
2011-06-01Ensure list_display works on outputs of unknown widthDan McGee1-1/+1
If getcols() returns 0, we were getting stuck before in a loop of no return. Teach getcols() to take a default value to return if the width is unknown, and use this everywhere as appropriate. Also make a few other cleanups while diagnosing this issue, such as const-ifying some variables. Noticed-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-04-21Table formatted output functionsJakob Gruber1-0/+1
table_display takes a list of lists of strings (representing the table cells) and displays them formatted as a table. The exact format depends on the longest string in each column. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-04-21Add a utility function to humanize sizesJakob Gruber1-0/+1
Converts the given size in bytes in two possible ways: 1) target_unit is specified (!= 0): size is converted to target unit. 2) target_unit is not specified (== '\0'): size is converted to the first unit which will bring size to below 2048. If specified, label will point to the long label ('MB') if long_labels is set or the short label ('M') if it is not. Dan: use '\0' rather than 0 for the special value as a matter of coding style for char variables. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-01-29pacman/sync: implement interactive group selectionXavier Chantry1-0/+1
Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
2011-01-29Add interactive provider selectionXavier Chantry1-0/+2
If there are multiple providers in one db, pacman used to just stop at the first one (both during dependency resolution or for pacman -S 'provision' which uses the same code). This adds a new conversation callback so that the user can choose which provider to install. By default (user press enter or --noconfirm), the first provider is still chosen, so for example the behavior of sync402 and 403 is preserved. But at least the user now has the possibility to make the right choice in a manual run. If one of the provider is already installed, it is picked for reinstall/upgrade, so that provision 002/003 pactest now pass. $ pacman -S community/smtp-server :: There are 3 providers available for smtp-server: 1) courier-mta 2) esmtp 3) exim Which one do you want to install? Enter a number (default=1): Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
2011-01-22Improve mbasename performanceDan McGee1-1/+1
Rather than roll our own, use strrchr() instead, which glibc may have a better implementation than the simple iteration method we were using. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-01-08Update copyright years for 2011Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2010-12-13pacman: sort --help outputXavier Chantry1-0/+1
Example with pacman -Uh : $ pacman -Uh options: -b, --dbpath <path> set an alternate database location -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -k, --dbonly only modify database entries, not package files -r, --root <path> set an alternate installation root -v, --verbose be verbose --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print only print the targets instead of performing the operation --print-format <string> specify how the targets should be printed Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com> [Dan: small coding style touchups] Signed-off-by: Dan McGee <dan@archlinux.org>