summaryrefslogtreecommitdiff
path: root/src/pacman/util.c
Commit message (Collapse)AuthorAge
* 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>
* | cygwin fix : use unsigned char for ctype functionXavier Chantry2009-10-11
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Minor scope/typing cleanupsDan McGee2009-10-11
| | | | | | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* | Remove transaction typeXavier Chantry2009-09-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | rewrite strreplaceXavier Chantry2009-09-07
| | | | | | | | | | | | | | | | | | | | | | | | * just do one malloc call * p = realloc(p, new_size) was not good (see http://www.iso-9899.info/wiki/Why_not_realloc) * use more efficient strncpy instead of strncat Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Don't wrap lines when we don't have a column sizeOleg Finkelshteyn2009-09-06
|/ | | | | | | | | | | | | | For example when we are not in a tty, there is no point in wrapping the output. This actually makes the job harder for scripts. $ pacman -Si binutils | grep Desc Description : A set of programs to assemble and manipulate binary and The description was cut because the rest was on the following line. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> [Dan: use printf everywhere] Signed-off-by: Dan McGee <dan@archlinux.org>
* Update copyright headers and messagesDan McGee2009-07-01
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* We don't need root with -SpNagy Gabor2009-06-01
| | | | | | | | | | | | FS#8905 is fixed. The front-end passes PM_TRANS_FLAG_NOLOCK to the back-end, so it doesn't lock the database. That's why we don't need root anymore. I reworked (and renamed) needs_transaction() accordingly. I also added missing -Sc check there (for example, -Sci didn't print non-root error, but pacman wanted to lock the database). Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove pmsyncpkg_tNagy Gabor2009-04-11
| | | | | | | | | | | | | | | | | | | | | pmsyncpkg_t data sructure was removed: 1. pmpkg_t.reason is used instead of pmsyncpkg_t.newreason. (The target packages come from sync repos, so we can use this field without any problems. Upgrade transaction also uses this field to store this info.) 2. pmsyncpkg_t.removes was moved to pmpkg_t.removes. This step requires careful programming, because we don't duplicate packages when we add them to trans->packages. So we modify sync pkgcache when we add this transaction-only info to our package. Hence it is important to free this list when we remove any package from the target list (remove_unresolvable, remove_conflicts, trans_free), otherwise this could confuse the new sync transactions (with non-pacman GUI). Overall, our code became ~100 line shorter, and we can call our helper functions directly on trans->packages in sync.c, we don't need to maintain parallel package lists. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge branch 'maint'Dan McGee2008-10-12
|\
| * Reduce number of calls to getcols()Dan McGee2008-10-12
| | | | | | | | | | | | | | Every call to getcols() results in two ioctl() calls, which we really didn't need as changing the number of columns in mid-print would be pretty crazy. Signed-off-by: Dan McGee <dan@archlinux.org>
* | pacman : smarter optdepends handling.Xavier Chantry2008-08-25
| | | | | | | | | | | | | | | | | | | | During an upgrade, only the new optdepends will be displayed, to only keep the useful information and not clutter pacman output too much. The whole optdepends list is always available with -Si / -Qi. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Merge branch 'maint'Dan McGee2008-08-23
|\|
| * Fix 'None' text so we don't have to translate it twiceDan McGee2008-08-23
| | | | | | | | | | | | | | We had one "None" and one "None\n" string; we can let the program do the addition of the newline so we don't have to. Signed-off-by: Dan McGee <dan@archlinux.org>
* | split yesno() into yesno() and noyes() functions.Xavier Chantry2008-08-23
|/ | | | | | | | | | | | | | | | The yesno function had a preset argument for specifying the default answer : yes or no. However, in all our calls to yesno, only one used the default "no" answer. Having to specify preset==1 for all the other cases was rather cumbersome. To make this easier, this commit adds a noyes function, with the following behavior : yesno() : default answer is yes noyes() : default answer is no Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* pacman: print optdepends on install and upgrade.Xavier Chantry2008-08-23
| | | | | | | This implements FS#10630. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Add new list_display_linebreak functionNagy Gabor2008-08-23
| | | | | | | | | | | | | | | | | | | | list_display puts several members on the same line, which is not appropriate for optdepends: Optdepends: foo: feature1 bar: feature2 baz: feature3 The new list_display_linebreak function puts every member on its own line, which is much better with optdepends: Optdepends: foo: feature1 bar: feature2 baz: feature3 Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Xav: implement this new behavior as a new function rather than as a parameter of list_display] Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Move the the description parsing logic to string_display()Nagy Gabor2008-08-23
| | | | | | | | | So dump_pkg_full will indent all strings correctly. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Xav: add string_length function] Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Show number of packages to be installed / removed.Xavier Chantry2008-07-24
| | | | | | | This fixes FS#7794. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* src/pacman : rework the display_targets function.Xavier Chantry2008-07-24
| | | | | | | | | | | | | | | | | | | | We had a lot of duplicated code here. The code handling the showsize option needed to be there three times : 1) for install part of -S 2) for remove part of -S (conflict removal) 3) for -R This patch introduce a new display_targets(pkglist, install) function which can handle the 3 cases above. We pass install == 1 for case 1), and install == 0 for case 2) and 3). Now we can finally get the benefit of an old patch which handled the ShowSize option consistently in the 3 cases above, without an awful lot of duplicated code : http://www.archlinux.org/pipermail/pacman-dev/2008-January/011029.html Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Use access() instead of stat() when possibleDan McGee2008-06-15
| | | | | | | | | | | | | | | | | | | We were using the stat() system call in quite a few places when we didn't actually need anything the stat struct returned- we were simply checking for file existence. access() will be more efficient in those cases. Before (strace pacman -Ss pacman): % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 33.16 0.005987 0 19016 stat64 After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 34.85 0.003863 0 12633 1 access 7.95 0.000881 0 6391 7 stat64 Signed-off-by: Dan McGee <dan@archlinux.org>
* Use correct C type for file sizesDan McGee2008-06-04
| | | | | | | | | | | | | | We have been using unsigned long as a file size type for a while, which works but isn't quite correct and could easily break. Worse was probably our use of int in the download callback functions, which could be restrictive for packages > 2GB in size. Switch all file size variables to use off_t, which is the preferred type for file sizes. Note that at least on Linux, all applications compiled against libalpm must now be sure to use large file support, where _FILE_OFFSET_BITS is defined to be 64 or there will be some weird issues that crop up. Signed-off-by: Dan McGee <dan@archlinux.org>
* Make all error messages use pm_fprintfAllan McRae2008-05-11
| | | | | | | | | | Tested using many easily generated error conditions. Also added "malloc failure" (conf.c) and "segmentation fault" (pacman.c) error messages for translation. Signed-off-by: Allan McRae <mcrae_allan@hotmail.com> [Dan: fix trailing whitespace errors, other compilation issues] Signed-off-by: Dan McGee <dan@archlinux.org>
* Update makepath to remove PATH_MAX usageDan McGee2008-05-10
| | | | | | | The start of a few commits to remove some PATH_MAX usage from our code. Use a dynamically allocated string instead. Signed-off-by: Dan McGee <dan@archlinux.org>
* Completely rework delta algorithmChantry Xavier2008-04-26
| | | | | | | | | | | | | | | | | | | | Using the graph structures that Nagy set up for dependency sorting, we now do a similar process for deltas. Load up all of the deltas into a graph object on which we can then apply Dijkstra's algorithm, using the new weight field of graph struct. We initialize the nodes weight using the base files that we can use in our filecache (both filename and md5sum must match). The algorithm then picks the best path among those that can be resolved. Note that this algorithm has a few advantages over the old one: 1. It is completely file agnostic. These delta chains do not have to consist of package files- this could be adopted to do delta-fied DBs. 2. It does not use the local_db anymore, or even care if a package or file is currently installed. Instead, it only looks in the filecache for files and packages that match delta chain entries. Original-work-by: Dan McGee <dan@archlinux.org> Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
* Refactor the trans init and release code.Chantry Xavier2008-04-26
| | | | | | | | | | | | | The calls to alpm_trans_init and alpm_trans_release (+ error checking) were duplicated between remove.c, sync.c and upgrade.c This patch introduces trans_init and trans_release functions in util.c to have this code just once. So instead of having to do the same change 3 times for fixing FS#10273, I just had to do it once (so I did it too :)) Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge branch 'maint'Dan McGee2008-03-23
|\
| * strsplit(): memleak fixDan McGee2008-03-23
| | | | | | | | | | | | We dup-ed the string but then duped it again. Fix it. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Improve yesno function.Chantry Xavier2008-02-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a preset paramater to yesno function saying which answer should be the default. Ref: http://www.archlinux.org/pipermail/pacman-dev/2007-June/008470.html This allows us to answer no by default to some questions, like the -Scc one mentioned in the above thread, and implemented by this patch. Another advantage is that we don't have to repeat the [Y/n] in every questions. It's only put once in yesno function. This highly reduces the chances that YES and NO strings are translated, but not some questions, which lead to obvious confusions. Finally, the noconfirm variable only needs to be used in that yesno function. So all other usages of it were removed. Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
* | Merge branch 'maint'Dan McGee2008-02-24
|\| | | | | | | | | | | Conflicts: src/pacman/callback.c
| * Add some NULL checks into recently modified output functionsDan McGee2008-02-24
| | | | | | | | | | | | | | | | | | After a merge with master where some strings we print (such as descriptions) could be NULL, a few segfaults popped up due to strlen() calls on null pointers. Fix this by doing some preemptive checks and returning from functions early if the string was null. Signed-off-by: Dan McGee <dan@archlinux.org>
| * A few more wide character output fixesDan McGee2008-02-22
| | | | | | | | | | | | | | Fix up the indentprint and list printing functions so they work properly. This output can be seen in places such as -Ss, -Si, -Qs, and -Qi. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Merge branch 'maint'Dan McGee2008-02-05
|\| | | | | | | | | | | | | Conflicts: contrib/gensync contrib/updatesync
| * pacman/util.c: add mdirname functionDan McGee2008-02-05
| | | | | | | | | | | | This function mirrors mbasename and will be used by the 'owns' machinery. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Remove "Installed Size" hackerationDan McGee2008-02-05
| | | | | | | | | | | | | | Keeping this hack around where installed size is only shown if it is greater than total download size encourages broken repository databases. Signed-off-by: Dan McGee <dan@archlinux.org>
* | pmsyncpkg_t cleanupNagy Gabor2008-01-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix for sync044.py and reason001.py. Rename sync->data to sync->removes (alpm_list_t *) Replace pmsynctype_t sync->type by pmpkgreason_t sync->newreason The type field was set to UPGRADE or DEPEND or REPLACE. Instead of using type = UPGRADE or DEPEND, we now rather use a "pmpkgreason_t newreason" field directly (= explicit or depend) which allows a better handling of the install reason. And the REPLACE type is now deduced implicitly when the sync->removes list is not empty. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Merge branch 'maint'Dan McGee2008-01-21
|\|
| * Remove frontend translation of "debug:" messageDan McGee2008-01-20
| | | | | | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* | Use dynamic string allocation in package structuresDan McGee2008-01-11
|/ | | | | | | | | | | | | | This also affects all structures with static strings, such as depmiss, conflict, etc. This should help a lot with memory usage, and hopefully make things a bit more "idiot proof". Currently our pactest pass/fail rate is identical before and after this patch. This is not to say it is a perfect patch- I have yet to pull valgrind out. However, this should be quite safe to use in all situations from here on out, and we can start plugging the memleaks. Original-work-by: Aaron Griffin <aaronmgriffin@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Update GNU GPL boilerplate and copyright datesDan McGee2007-12-10
| | | | | | | Update the GPL boilerplate to direct people to the GNU website for a copy of the license, as well as bump all of Judd's copyrights to 2007. Signed-off-by: Dan McGee <dan@archlinux.org>
* Delay output during progress barChantry Xavier2007-12-03
| | | | | | | | | | This fixes the output issue related to the progress bar by delaying the output. We can decide later (post-release) if we like this method or we want to switch to something else. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> [Dan: just some minor cleanups] Signed-off-by: Dan McGee <dan@archlinux.org>
* Unify dump_pkg_full in pacman [-Si, -Qip, -Qi and -Qii]Nagy Gabor2007-12-01
| | | | | | | | | | | | | dump_pkg_sync is now a trivial wrapper for dump_pkg_full Some smaller changes: * string_display function added to util.c [prints None in case of empty string] * Filename field added to -Qip * rename License to Licenses * 'Compressed Size' used instead of 'Download Size' for -Qip Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Dan: fix whitespace errors, spacing issues, const modifiers] Signed-off-by: Dan McGee <dan@archlinux.org>
* Move mbasename from pacman.c to util.cChantry Xavier2007-11-25
| | | | | | | This function can be useful in other places. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* War on whitespaceDan McGee2007-11-16
| | | | | | Run the kernel's cleanfile script on all of our source files. Signed-off-by: Dan McGee <dan@archlinux.org>
* Make it easier to ignore multiple packages.Nathan Jones2007-11-13
| | | | | | | | | | | | This makes --ignore and --ignoregroup able to accept multiple packages/groups by separating each with a comma. For instance: pacman -Su --ignore kernel26,udev,glibc This was requested in the comments of FS#8054. Signed-off-by: Nathan Jones <nathanj@insightbb.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove 'Total Package Size'Dan McGee2007-11-11
| | | | | | | Having 'Total Installed Size' and 'Total Download Size' makes this size unnecessary. Signed-off-by: Dan McGee <dan@archlinux.org>