summaryrefslogtreecommitdiff
path: root/src/pacman/util.c
Commit message (Collapse)AuthorAge
* Fix all current return(x) usagesDan McGee2011-06-13
| | | | | | | | | A few of these snuck in as of late, some from the table display patches that were using the previous format before we changed it after the 3.5.X major release. Noticed-by: Kerrick Staley <mail@kerrickstaley.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Require handle argument to all alpm_trans_*() methodsDan McGee2011-06-09
| | | | | | | Begin enforcing the need to pass a handle. This allows us to remove one more extern handle declaration from the backend. Signed-off-by: Dan McGee <dan@archlinux.org>
* Require handle argument to all alpm_option_(get|set)_*() methodsDan McGee2011-06-09
| | | | | | | | This requires a lot of line changes, but not many functional changes as more often than not our handle variable is already available in some fashion. Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge branch 'maint'Dan McGee2011-06-02
|\ | | | | | | | | Conflicts: src/pacman/callback.c
| * Ensure list_display works on outputs of unknown widthDan McGee2011-06-01
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Show net upgrade size on -U/-S operationsDan McGee2011-06-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If it is different than the raw installed size metric we already show, compute the net upgrade size. For some sync operations, this can even be negative if newer packages are smaller than the ones they replace locally. Implements FS#12566. Example: Targets (1): telepathy-glib-0.14.7-1 Total Download Size: 1.07 MiB Total Installed Size: 15.72 MiB Net Upgrade Size: -0.29 MiB Signed-off-by: Dan McGee <dan@archlinux.org>
* | Fix warnings reported by -Wwrite-stringsDan McGee2011-05-04
| | | | | | | | | | | | | | These are places where we stuck a string constant in a variable not marked as const. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Header inclusion cleanupDan McGee2011-04-20
| | | | | | | | | | | | | | | | This does touch a lot of things, and hopefully doesn't break things on other platforms, but allows us to also clean up a bunch of crud that no longer needs to be there. Signed-off-by: Dan McGee <dan@archlinux.org>
* | syntax: if/while statements should have no trailing spaceDan McGee2011-04-20
| | | | | | | | | | | | | | | | | | | | | | This is the standard, and we have had a few of these introduced lately that should not be here. Done with: find -name '*.c' | xargs sed -i -e 's#if (#if(#g' find -name '*.c' | xargs sed -i -e 's#while (#while(#g' Signed-off-by: Dan McGee <dan@archlinux.org>
* | New VerbosePkgLists optionJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If enabled, displays package lists for upgrade, sync and remove operations formatted as a table. Falls back to default list display if insufficient terminal columns are available. Example output: :: Starting full system upgrade... :: Replace libjpeg with testing/libjpeg-turbo? [Y/n] resolving dependencies... looking for inter-conflicts... Remove (1): Name Old Version Size libjpeg 8.3.0-1 0.83 MB Total Removed Size: 0.83 MB Targets (5): Name Old Version New Version Size libjpeg-turbo 1.1.0-1 0.20 MB linux-firmware 20110201-1 20110227-1 8.23 MB ncurses 5.7-4 5.8-1 0.92 MB ppl 0.11.1-1 0.11.2-1 2.74 MB v4l-utils 0.8.1-1 0.8.3-1 0.23 MB Total Download Size: 12.32 MB Total Installed Size: 58.82 MB Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Table formatted output functionsJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | | | 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>
* | Refactor display_targets for readabilityJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | Row handling is moved to its own function in preparation for verbose package lists. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Use IEC unit prefixesJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | Display {KiB, MiB, ...} instead of {KB, MB, ...} since that's what's actually being displayed. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Add a utility function to humanize sizesJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Remove ShowSize optionJakob Gruber2011-04-20
| | | | | | | | | | | | | | | | | | | | Dan: The commit message originally referenced "VerbosePkgLists", but I'm going to change the name of the option. In addition, this patch serves a purpose being standalone- we should really do things like this with -S --print and hopefully -Q --print in the future. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Merge branch 'maint'Dan McGee2011-04-05
|\| | | | | | | | | | | | | Conflicts: lib/libalpm/be_sync.c lib/libalpm/db.c src/pacman/util.c
| * Coding style cleanupsDan McGee2011-04-04
| | | | | | | | Signed-off-by: Dan McGee <dan@archlinux.org>
| * Ensure stdout/stderr are flushed when asking questionsDan McGee2011-04-01
| | | | | | | | | | | | | | | | | | Addresses FS#23492, where the question was shown without knowing what one was answering to. Ensure we flush our output streams before printing the question, and flush the stream on which we ask the question before waiting for an answer. Signed-off-by: Dan McGee <dan@archlinux.org>
* | pacman/util: flush terminal input before reading responseDave Reisner2011-03-28
| | | | | | | | | | | | | | Addresses FS#20538 Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Style change: return(x) --> return xDan McGee2011-03-20
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was discussed and more or less agreed upon on the mailing list. A huge checkin, but if we just do it and let people adjust the pain will end soon enough. Rebasing should be relatively straighforward for anyone that sees conflicts; just be sure you use the new return style if possible. The following semantic patch was used to do the change, along with some hand-massaging in order to preserve parenthesis where appropriate: The semantic match that finds this problem is as follows, although some hand-massaging was done in order to keep parenthesis where appropriate: (http://coccinelle.lip6.fr/) // <smpl> @@ expression a; @@ - return(a); + return a; // </smpl> A macros_file was also provided with the following content: Additional steps taken, mainly for ASSERT() macros: $ sed -i -e 's#return(NULL)#return NULL#' lib/libalpm/*.c $ sed -i -e 's#return(-1)#return -1#' lib/libalpm/*.c Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix some easy to find double translationsDan McGee2011-02-28
| | | | | | | | A lot of these were places that should have used the same message but didn't, or were very easy to convert to using the same message and letting some of the burden off of the translators. Signed-off-by: Dan McGee <dan@archlinux.org>
* --print-format displays size in bytesJakob Gruber2011-02-28
| | | | | | | | Printing the exact size seems to make more sense for scripting contexts. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> [Dan: adjust for master before VerbosePkgLists patches, fix type] Signed-off-by: Dan McGee <dan@archlinux.org>
* Check local DB version before continuing transactionDan McGee2011-02-28
| | | | | | | | | Ensure we have a local DB version that is up to par with what we expect before we go down any road that might modify it. This should prevent stupid mistakes with the 3.5.X upgrade and people not running pacman-db-upgrade after the transaction as they will need to. Signed-off-by: Dan McGee <dan@archlinux.org>
* select_display: per-database outputXavier Chantry2011-01-29
| | | | | | | | | | | | | | | | This function is used both for provision and group selection. Now the database name will be displayed. $ pacman -S base-devel :: There are 11 members in group base-devel: :: Repository testing 1) make :: Repository core 2) autoconf 3) automake 4) bison 5) fakeroot 6) flex 7) gcc 8) libtool 9) m4 10) patch 11) pkg-config Which ones do you want to install? Enter a number (default=all): Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
* pacman: improve select-questionXavier Chantry2011-01-29
| | | | | | | Make use of parseindex like in multiselect, and loop until we get a valid answer like in multiselect. Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
* pacman/sync: implement interactive group selectionXavier Chantry2011-01-29
| | | | Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
* Add interactive provider selectionXavier Chantry2011-01-29
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* Improve mbasename performanceDan McGee2011-01-22
| | | | | | | 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>
* Small fix to download size lookup and a loggerDan McGee2011-01-11
| | | | | | | | These were just two small things I came across today and found could be fixed or helpful, so I've added them and I'm not sure what else to bundle them with. commit_count++ Signed-off-by: Dan McGee <dan@archlinux.org>
* Use double rather than float everywhereDan McGee2011-01-10
| | | | | | No real need to use the smaller floating point types here. Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix some more simple conversion "errors"Dan McGee2011-01-07
| | | | | | | | None of these warn at the normal "-Wall -Werror" level, but casts do occur that we are fine with. Make them explicit to silence some warnings when using "-Wconversion". Signed-off-by: Dan McGee <dan@archlinux.org>
* Update copyright years for 2011Allan McRae2011-01-07
| | | | | Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix a few problems reported by clang-analyzerXavier Chantry2010-12-12
| | | | | | | One missing NULL-check and 3 dead assignments. Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Add wrapper around asprintf callsAllan McRae2010-09-27
| | | | | | | | | | | Not checking the return value of asprintf calls reuslts in a warning when using -D_FORTIRFY_SOURCE=2. This adds a simple wrapper around asprintf calls which checks the return value. Currently the check does nothing more than outputing a message to stderr on failure, but that is at least an improvement over silent failures. Signed-off-by: Allan McRae <allan@archlinux.org>
* Fix some whitespace issuesAllan McRae2010-08-23
| | | | | | | | The combination of tabs and spaces is annoying in any editor that does not use a tab width of 2 spaces. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* fgets invocation cleanupDan McGee2010-08-23
| | | | | | | | | | | | | | From the fgets manpage: fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer. This means there is no need at all to do 'size - 1' math. Remove all of that and just use sizeof() for simplicity on the buffer we plan on reading into. Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge branch 'maint'Dan McGee2010-07-27
|\
| * Fix compile error in certain casesDan McGee2010-07-27
| | | | | | | | | | | | | | | | | | | | | | | | | | I'm not sure why it doesn't happen everywhere, but we need <sys/stat.h> for umask and mkdir in this file. I hit this today: cc1: warnings being treated as errors util.c: In function ‘makepath’: util.c:128:2: error: implicit declaration of function ‘umask’ util.c:141:5: error: implicit declaration of function ‘mkdir’ make[2]: *** [util.o] Error 1 Signed-off-by: Dan McGee <dan@archlinux.org>
* | Clarify testing within conditional statementsAllan McRae2010-06-21
|/ | | | | | | | | Follow the HACKING guidelines and always use != 0 or == 0 rather than negation within conditional statements to improve clarity. Most of these are !strcmp usages which is the example of what not to do in the HACKING document. Signed-off-by: Allan McRae <allan@archlinux.org>
* Introduce -D, --databaseNagy Gabor2010-05-05
| | | | | | | | | | | | | The request of FS#12950 is implemented. On the backend side, I introduced a new function, alpm_db_set_pkgreason(), to modify the install reason of a package in the local database. On the front-end side, I introduced a new main operation, -D/--database, which has two options, --asdeps and --asexplicit. I documented this in pacman manual. I've created two pactests to test -D: database001.py and database002.py. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* Bump copyright dates to 2010Dan McGee2010-03-14
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* fix a few warnings reported by clangXavier Chantry2010-03-14
| | | | | | | | | - remove unused variables - some more sanity checks - safer printf Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Mark two functions staticDan McGee2010-03-14
| | | | | | | These were just introduced in the `--print` patch, and don't need to be exposed outside of util.c. Signed-off-by: Dan McGee <dan@archlinux.org>
* Add new --print operation for all operationsXavier Chantry2010-03-14
| | | | | | | | | | | | | And a new --print-format option to configure the output. This implements FS#14208 Example usage : pacman -Sp --print-format "%r/%n-%v : %l [%s]" kdelibs extra/kdelibs-4.3.2-4 : ftp://mir2.archlinuxfr.org/archlinux/extra/os/i686/kdelibs-4.3.2-4-i686.pkg.tar.gz [0,00] Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Do not print installed size when only downloadingAllan McRae2010-01-19
| | | | | | | | When using --downloadonly the "Total Installed Size" message is not needed and perhaps misleading. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove trailing whitespace on all lines in list_displayDan McGee2009-12-13
| | | | | | | | | | | | | | | | This ensures we never have trailing whitespace. Take the following text, with line numbers added for clarity: 1. Title : item1 item2 item3 item4 2. item5 item6 item7 item8 3. item9 itemA itemB itemC Laszlo Papp helpfully pointed out we would have two trailing spaces on line three after the last item. However, we also had these trailing spaces on lines one and two, which the initial patch didn't take care of. This can be seen on something like `pacman -Qi glibc`. Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge branch 'maint'Dan McGee2009-11-10
|\
| * Fix opendir error condition checksDan McGee2009-10-27
| | | | | | | | | | | | | | | | | | | | Thanks to Laszlo Papp <djszapi@archlinux.us> for the following catch: opendir(path)) == (DIR *)-1; is maybe the result of misunderstanding the manpage. If an opendir() call isn't successful it returns NULL rather than '(DIR *)-1'. Noticed-by: Laszlo Papp <djszapi@archlinux.us> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Size handling was changed in fgets() functionsLaszlo Papp2009-10-19
| | | | | | | | | | | | | | | | Pacman's fgets function in the API used hardcoded numbers to identify the size. This is not good practice, so replace them with sizeof handling. Signed-off-by: Laszlo Papp <djszapi@archlinux.us> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Remove makepath function from frontendLaszlo Papp2009-10-11
| | | | | | | | Signed-off-by: Dan McGee <dan@archlinux.org>