summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
AgeCommit message (Collapse)AuthorFilesLines
2012-02-20Give better error messages on database locking failuresDan McGee1-3/+7
This was noted when trying to perform an operation on a pacman database on a read-only file system. Print the actual underlying errno string, and only show the "you can remove" message if the lock file actually exists. Before: $ pacman -Su error: failed to init transaction (unable to lock database) if you're sure a package manager is not already running, you can remove /e/db.lck After: $ pacman -Su error: failed to init transaction (unable to lock database) error: could not lock database: Read-only file system Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-07Fix a handful of comment typos or misspellingsDan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-03Add simple integer-only pow() implementationDan McGee1-2/+13
We hardly need the complexity (or slowness) provided by the libm power function; add a super-cheap one that suits our needs and is specialized for the values we plan on passing in. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-03Fix FS#27924: don't display negative zeroesThomas Dziedzic1-8/+16
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-19Update copyright on changed files since beginning of yearDan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-19util.c, rmrf(): only create string when neededOlivier Brunel1-3/+3
The entry's name is only used when not "." or ".." so only print the string then. Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-19Fix missing [removal] outputAllan McRae1-1/+5
Currently, a transaction is considered to be purely package removal until the first package install is found. This resulted in the removed packages at the start of a combined upgrade/removal transaction not getting the "[removal]" output. Fixes FS#27981. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-19Fix broken output when asking question and stdin is pipedOlivier Brunel1-0/+6
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it. Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-18Remove unused strtoupper() functionDan McGee1-13/+0
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-21Remove remaining usages of fprintf() from frontendDan McGee1-2/+3
These can either be replaced with pm_printf() if they are error related, or in the fprintf(stdout, ...) case a bare printf() will do. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-21Remove pm_fprintf() in favor of pm_printf()Dan McGee1-18/+5
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-10-21Use stderr as output stream for pm_printf()Dan McGee1-1/+1
This matches what we now do in our backend callback function- all debug/info/warning/error/etc. messages should be on stderr. These are all the messages with a "warning:" or other type prefix, so does not affect general pacman output. This should fix the output confusion noted in FS#26555. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-17Table display: print message with warning: prefixDan McGee1-1/+2
Use the normal error functions here rather than a bare fprintf(). Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-13Coding style cleanupsDan McGee1-5/+5
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-12VerbosePkgLists: format table lines in i18n-compatible wayDan McGee1-43/+48
This had the unfortunate implementation detail that depended on the strings having 1 byte == 1 column hold true. As we know, this is not at all the case once you move past the base ASCII character set. Reimplement this whole thing so it doesn't depend on format strings at all. Instead, simply calculate the max column widths, and then when displaying each row add the correct amount of padding using UTF-8 safe string length functions. Before: 名字 旧版本新版本 净变化 下载大小 libgee 0.6.2.1-1 0.60 MiB 0.10 MiB libsocialweb 0.25.19-2 1.92 MiB 0.23 MiB folks 0.6.3.2-1 1.38 MiB 0.25 MiB After: 名字 旧版本 新版本 净变化 下载大小 libgee 0.6.2.1-1 0.60 MiB 0.10 MiB libsocialweb 0.25.19-2 1.92 MiB 0.23 MiB folks 0.6.3.2-1 1.38 MiB 0.25 MiB Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-30Remove redundant transaction size outputAllan McRae1-1/+1
Printing all of "Installed", "Removed" and "Net Upgrade" sizes is redundant as the difference of the first two is the last. Instead, only print "Installed Size" and "Net Upgrade Size" when both the installed and removed are non-zero. This results in the following output in the following cases: - package installation only: Installed Size - package removal only: Removed Size - package installation involving replacement: Installed + Net Upgrade Size - package upgrade: Installed + Net Upgrade Size - combination upgrade and installation: Installed + Net Upgrade Size Download Size remains outputted whenever something is downloaded. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-29Remove redundant "removal" output in pure remove operationAllan McRae1-0/+3
Printing "[removal]" beside all package names is redundant when all packages are being removed (i.e. when using -R). Signed-off-by: Allan McRae <allan@archlinux.org>
2011-09-28Refactor display_targets to not be recursiveDan McGee1-33/+26
This also fixes a memory leak and makes the dual-purpose "rows" variable go away in favor of storing the rows and non-verbose names separately. This also fixes some potential memory leaks and/or wrong behavior due to the config->verbosepkglists flag being flipped, which we should never be doing. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28verbose package lists: remove errant debuggerDan McGee1-2/+0
Left this in as part of the last set of commits, whoops. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Always show download size if -w/--downloadonly was providedDan McGee1-2/+2
The prompt can be rather confusing otherwise when all files have already been downloaded, but there is not a single total size listed. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Table format creation code cleanupDan McGee1-21/+27
Better scoping of variables for the most part, and ensure we are using string_length() and not strlen() as appropriate. Also refactor the longest cell code to call string_length() a lot less; by simply using an array of max sizes we don't have to recompute values nearly as much. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Use unsigned types for indent width and column countDan McGee1-22/+22
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-28Show download sizes when using -S/--syncDan McGee1-5/+21
We now label the old 'Size' column as 'Net Change' to reflect the reality of what we are looking at. Sync operations now get an additional 'Download Size' column. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28Keep track of explicitly added and removed packagesDan McGee1-0/+18
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-60/+102
There was no real reason for these to be done separately. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-22Add status and check for key being disabledDan McGee1-0/+3
Because we aren't using gpgv and a dedicated keyring that is known to be all safe, we should honor this flag being set on a given key in the keyring to know to not honor it. This prevents a key from being reimported that a user does not want to be used- instead of deleting, one should mark it as disabled. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-22Fix signature printing in package infoDan McGee1-1/+1
pm_asprintf() does not return a length as asprintf() does. Fail. Make sure it is not -1 as that is the only failure condition. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-20pacman: use dynamic string allocation where it makes senseDan McGee1-2/+8
None of these are hot-code paths, and at least the target reading has little need for an arbitrary length limitation (however crazy it might be to have longer arguments). Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-15Don't duplicate header stringsDan McGee1-5/+5
There is no need to print them into buffers; we can use the values returned by gettext() directly without issue. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-03Move all callbacks up to the handle levelDan McGee1-7/+1
This was just disgusting before, unnecessary to limit these to only usage in a transaction. Still a lot of more room for cleanup but we'll start by attaching them to the handle rather than the transaction we may or may not even want to use these callbacks. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-30Improve advice for sync ops when db.lck is presentPang Yan Han1-9/+13
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-7/+8
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-26strtrim: don't move empty stringDan McGee1-1/+6
There were many cases where the string coming in was a blank line, e.g. "\n\0", length 1. The trim routine starts by trimming leading spaces, thus trimming everything. We would then proceed to do a memmove of the NULL byte, which is completely worthless as we can just assign it instead. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-25Remove short/long label distinctionDan McGee1-13/+9
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-08-25Add a few more sizes to humanize_sizes()Dan McGee1-2/+4
Because why the hell not? Exbibyte, zebibyte, and yobibyte are going in, even though nothing bigger than the 2^60 exbibyte can be represented using an off_t variable anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-22pacman/util: use string_length to calculate line lengthDave Reisner1-1/+1
This is measuring strings that are potentially localized, so we need a multibyte aware function to count characters instead of bytes. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-22Print debug timestamps to same stream as rest of outputDan McGee1-1/+1
We used fprintf() elsewhere in this function, but we didn't use it on the debug timestamp printing. Use fprintf() instead of printf() to fix this. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-11Update trust level strings in -Qi displayDan McGee1-3/+3
It makes more sense to use the same tense and construction on all of these. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-09Merge branch 'maint'Dan McGee1-3/+35
Conflicts: lib/libalpm/dload.c lib/libalpm/po/fi.po lib/libalpm/po/libalpm.pot po/de.po po/fi.po src/pacman/po/pacman.pot src/pacman/util.c
2011-07-29Revamp signing checksDan McGee1-11/+31
This ensures we are actually making correct use of the information gpgme is returning to us. Marginal being allowed was obvious before, but Unknown should deal with trust level, and not the presence or lack thereof of a public key to validate the signature with. Return status and validity information in two separate values so check methods and the frontend can use them independently. For now, we treat expired keys as valid, while expired signatures are invalid. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-25Fix group selection entry for large inputsDan McGee1-3/+35
Hardcoding anything always ends up burning you, and the arbitrary length of 64 here did just that. Add the ability to reallocate the readline buffer for longer inputs if necessary, and add other error checking as approprate. This also plugs one small memory leak of the group processing code selection array. Addresses FS#24253. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-06Remove most usages of strncmp()Dan McGee1-7/+4
The supposed safety blanket of this function is better handled by explicit length checking and usages of strlen() on known NULL-terminated strings rather than hoping things fit in a buffer. We also have no need to fully fill a PATH_MAX length variable with NULLs every time as long as a single terminating byte is there. Remove usages of it by using strcpy() or memcpy() as appropriate, after doing length checks via strlen(). Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-05Remove alpm_list_firstAllan McRae1-1/+1
The only thing this accessor did was remove the const qualifier given our entire list implementation requires passing around the head anyway. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-05Allow invalid sync DBs to be returned by the libraryDan McGee1-1/+29
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-1/+47
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-07-01Prefix _alpm_errno_t members with ALPMAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-07-01Prefix alpm_transflag_t members with ALPMAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-07-01Prefix alpm_loglevel_t members with ALPMAllan McRae1-12/+12
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmerrno_t to alpm_errno_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmtransflag_t to alpm_transflag_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>