summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
AgeCommit message (Collapse)AuthorFilesLines
2011-06-03Merge branch 'maint'Dan McGee1-12/+10
Conflicts: src/pacman/callback.c
2011-06-03Show net upgrade size on -U/-S operationsDan McGee1-1/+12
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>
2011-06-01Ensure list_display works on outputs of unknown widthDan McGee1-11/+9
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-05-04Fix warnings reported by -Wwrite-stringsDan McGee1-2/+3
These are places where we stuck a string constant in a variable not marked as const. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-04-21Header inclusion cleanupDan McGee1-1/+0
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>
2011-04-21syntax: if/while statements should have no trailing spaceDan McGee1-5/+5
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>
2011-04-21New VerbosePkgLists optionJakob Gruber1-6/+85
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>
2011-04-21Table formatted output functionsJakob Gruber1-0/+110
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-21Refactor display_targets for readabilityJakob Gruber1-12/+10
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>
2011-04-21Use IEC unit prefixesJakob Gruber1-2/+2
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>
2011-04-21Add a utility function to humanize sizesJakob Gruber1-8/+46
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-04-21Remove ShowSize optionJakob Gruber1-10/+2
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>
2011-04-05Merge branch 'maint'Dan McGee1-5/+13
Conflicts: lib/libalpm/be_sync.c lib/libalpm/db.c src/pacman/util.c
2011-04-05Coding style cleanupsDan McGee1-5/+8
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-04-01Ensure stdout/stderr are flushed when asking questionsDan McGee1-0/+5
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>
2011-03-28pacman/util: flush terminal input before reading responseDave Reisner1-0/+21
Addresses FS#20538 Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-03-21Style change: return(x) --> return xDan McGee1-61/+61
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>
2011-03-01Fix some easy to find double translationsDan McGee1-10/+9
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>
2011-02-28--print-format displays size in bytesJakob Gruber1-2/+2
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>
2011-02-28Check local DB version before continuing transactionDan McGee1-0/+4
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>
2011-01-29select_display: per-database outputXavier Chantry1-2/+22
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>
2011-01-29pacman: improve select-questionXavier Chantry1-15/+16
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>
2011-01-29pacman/sync: implement interactive group selectionXavier Chantry1-0/+108
Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
2011-01-29Add interactive provider selectionXavier Chantry1-0/+55
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-13/+5
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-12Small fix to download size lookup and a loggerDan McGee1-1/+3
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>
2011-01-10Use double rather than float everywhereDan McGee1-2/+1
No real need to use the smaller floating point types here. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-01-08Fix some more simple conversion "errors"Dan McGee1-8/+7
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>
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-13Fix a few problems reported by clang-analyzerXavier Chantry1-1/+0
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>
2010-09-27Add wrapper around asprintf callsAllan McRae1-11/+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>
2010-08-24Fix some whitespace issuesAllan McRae1-1/+1
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>
2010-08-24fgets invocation cleanupDan McGee1-2/+1
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>
2010-07-27Merge branch 'maint'Dan McGee1-0/+1
2010-07-27Fix compile error in certain casesDan McGee1-0/+1
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>
2010-06-20Clarify testing within conditional statementsAllan McRae1-3/+3
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>
2010-05-05Introduce -D, --databaseNagy Gabor1-0/+2
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>
2010-03-15Bump copyright dates to 2010Dan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2010-03-15fix a few warnings reported by clangXavier Chantry1-1/+1
- 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>
2010-03-15Mark two functions staticDan McGee1-2/+2
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>
2010-03-15Add new --print operation for all operationsXavier Chantry1-9/+111
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>
2010-01-20Do not print installed size when only downloadingAllan McRae1-1/+3
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>
2009-12-14Remove trailing whitespace on all lines in list_displayDan McGee1-4/+6
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>
2009-11-11Merge branch 'maint'Dan McGee1-1/+2
2009-10-28Fix opendir error condition checksDan McGee1-1/+2
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>
2009-10-19Size handling was changed in fgets() functionsLaszlo Papp1-1/+2
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>
2009-10-11Remove makepath function from frontendLaszlo Papp1-36/+0
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-10-11cygwin fix : use unsigned char for ctype functionXavier Chantry1-3/+3
See http://www.nabble.com/-PATCH-RFA--Distinguish-between-EOF-and-character-with-value-0xff-td23161772.html#a23188494 cygwin 1.7 actually displays a warning when using signed char with the ctype function, so that compilation fails when using -Wall -Werror. So we just cast all arguments to unsigned char. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-10-11Minor scope/typing cleanupsDan McGee1-2/+2
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-09-09Remove transaction typeXavier Chantry1-33/+2
This basically started with this change : /* Transaction */ struct __pmtrans_t { - pmtranstype_t type; pmtransflag_t flags; pmtransstate_t state; - alpm_list_t *packages; /* list of (pmpkg_t *) */ + alpm_list_t *add; /* list of (pmpkg_t *) */ + alpm_list_t *remove; /* list of (pmpkg_t *) */ And then I have to modify all the code accordingly.