summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
Commit message (Collapse)AuthorAge
* Merge branch 'maint'Dan McGee2011-04-05
|\ | | | | | | | | | | | | Conflicts: lib/libalpm/be_sync.c lib/libalpm/db.c src/pacman/util.c
| * util.c: include limits.h for PATH_MAX macroRémy Oudompheng2011-04-02
| | | | | | | | | | Signed-off-by: Rémy Oudompheng <remy@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Merge branch 'maint'Dan McGee2011-03-23
|\|
| * Fix line_offset not being reset in _alpm_archive_fgets()Dan McGee2011-03-21
| | | | | | | | | | | | | | | | | | | | This is a rather serious data corruption issue that luckily manifested itself today in a noticable way. A package in testing had replaces entries read in as ["%RE pkgname", "%RE"] which was clearly wrong. This happens when we hit the end of an archive block, do not have a newline, and have to continue reading from the next block to complete the line. 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>
* Move locking functions to where they are neededDan McGee2011-02-28
| | | | | | | | We only call these from the transaction init and teardown, so move them to that file, mark them static, and push more of the logic of handle manipulation into these functions. Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix double close of the lock fileJonathan Conder2011-02-27
| | | | | | | | | | According to FOPEN(3), using fclose on an fdopen'd file stream also closes the underlying file descriptor. This happened in _alpm_lckmk (util.c), which meant that when alpm_trans_release closed it again, the log file (which reused the original file descriptor) was closed instead. Signed-off-by: Jonathan Conder <jonno.conder@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Add more error checking and loggingDan McGee2011-02-04
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Ensure found files are actually filesDan McGee2011-02-04
| | | | | | | | | We located files in a few places but didn't check if they were files or directories. Ensure they are actually files using stat() and S_ISREG(); this showed itself when trying to download to the directory name itself in FS#22645. Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix locale.h/setlocale inclusion with --disable-nlsDan McGee2011-02-01
| | | | | | | | | Noted in FS#22697. When I factored out _alpm_parsedate() into a common function, I didn't move the <locale.h> include properly, causing a build failure when NLS is disabled and this header isn't automatically included everywhere. Signed-off-by: Dan McGee <dan@archlinux.org>
* Improve splitname memory allocationDan McGee2011-01-21
| | | | | | | | We don't need to create a temporary copy of the string if we are smart with our pointer manipulation and string copying. This saves a bunch of string duplication during database parsing, both local and sync. Signed-off-by: Dan McGee <dan@archlinux.org>
* Add strndup fallback function to libalpm utilDan McGee2011-01-21
| | | | | | The same fallback we are currently using in the pacman frontend. 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>
* Refactor old date parsing into single methodDan McGee2011-01-07
| | | | | | | We've managed to duplicate this four times at this point, so make it a method in util.c instead. 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 function indentationDan McGee2011-01-02
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Overhaul archive fgets functionDan McGee2010-12-21
| | | | | | | | | | | | | | | | | | | | | | | | The old function was written in a time before we relied on it for nearly every operation. Since then, we have switched to the archive backend and now fast parsing is a big deal. The former function made a per-character call to the libarchive archive_read_data() function, which resulted in some 21 million calls in a typical "load all sync dbs" operation. If we instead do some buffering of our own and read the blocks directly, and then find our newlines from there, we can cut out the multiple layers of overhead and go from archive to parsed data much quicker. Both users of the former function are switched over to the new signature, made easier by the macros now in place in the sync backend parsing code. Performance: for a `pacman -Su` (no upgrades available), _alpm_archive_fgets() goes from being 29% of the total time to 12% The time spent on the libarchive function being called dropped from 24% to 6%. This pushes _alpm_pkg_find back to the title of slowest low-level function. Signed-off-by: Dan McGee <dan@archlinux.org>
* When setting package name, set hash value as wellDan McGee2010-12-14
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Add hash_sdbm functionDan McGee2010-12-14
| | | | | | | | This is prepping for the addition of a hash field to each package to greatly speed up the string comparisons we frequently do on package name in _alpm_pkg_find. Signed-off-by: Dan McGee <dan@archlinux.org>
* Turn libarchive warnings into libalpm warningsDan McGee2010-12-12
| | | | | | | | | | | | Rather than hiding these warnings, show them to the user as they happen. This will prevent things such as hiding full filesystem errors (ENOSPC) from the user as seen in FS#11639. Signed-off-by: Dan McGee <dan@archlinux.org> [Allan: adjust warning wording and add gettext calls] Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Move and rename splitnameAllan McRae2010-10-14
| | | | | | | | | The splitname function is a general utility function and so is better suited to util.h. Rename it to _alpm_splitname to indicate it is an internal libalpm function as was the case prior to splitting local and sync db handling. Signed-off-by: Allan McRae <allan@archlinux.org>
* Use OpenSSL MD5 crypto functions if availableDan McGee2010-09-02
| | | | | | | | | | | | | | | I've noticed my Atom-powered laptop is dog-slow when doing integrity checks on packages, and it turns out our MD5 implementation isn't near as good as that provided by OpenSSL. Using their routines instead provided anywhere from a 1.4x up to a 1.8x performance benefit over our built-in MD5 function. This does not remove the MD5 code from our codebase, but it does enable linking against OpenSSL to get their much faster implementation if it is available on whatever platform you are using. At configure-time, we will default to using it if it is available, but this can be easily changed by using the `--with-openssl` or `--without-openssl` arguments to configure. Signed-off-by: Dan McGee <dan@archlinux.org>
* use execv to avoid using sh just to run ldconfigJonathan Conder2010-08-27
| | | | | Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* redirect scriptlet stderr synchronously through alpmJonathan Conder2010-08-27
| | | | | | | | | Fixes FS#18770, and hopefully an occasional deadlock in my frontend as well. For simplicity it redirects all scriptlet output through SCRIPTLET_INFO, and all callbacks in the child process have been replaced for thread-safety. Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Check return value of chdir and getcwdAllan McRae2010-07-01
| | | | | | | Prevents compiler warnings when building with -D_FORTIFY_SOURCE=2 Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Check return value of fwrite when copying filesAllan McRae2010-06-30
| | | | | | | | | | | Check that writing to destination file actually occurs in _alpm_copyfile. Required adding a new error (PM_ERR_WRITE) as none of the others appeared appropriate. Prevents compiler warning when using -D_FORTIFY_SOURCE=2. Signed-off-by: Allan McRae <allan@archlinux.org> 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>
* Bump copyright dates to 2010Dan McGee2010-03-14
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Only extract new DB entriesXavier Chantry2010-03-14
| | | | | | | | | | | | | | | | | | | | | | | | This implements FS#15198. The idea apparently came from Csaba Henk <csaba-ml <at> creo.hu> which submitted a patch to Frugalware, so thanks to him, even though I did not look at the code :) The idea is to only extract folders for new packages into the package database and clean up the old directories. This is essentially implementing Xyne's "rebase" script within pacman. If using -Syy, just remove and extract everything. If using -Sy : 1. Generate list of directories in DB 2. Generate list of directories in archive 3. Compare both 4. Clean up old directories 5. Extract new directories Original-work-by: Allan McRae <allan@archlinux.org> Signed-off-by: Xavier Chantry <shiningxc@gmail.com> [Dan: fix compile error, s/int/size_t/] Signed-off-by: Dan McGee <dan@archlinux.org>
* Refactor do/while cycle and multiple while cyclesLaszlo Papp2009-11-15
| | | | | | | | * It makes the code clearer to read/understand * Cppcheck tool doesn't show this anymore: [./util.c:215]: (error) Resource leak: fd [Dan: don't change the coding style] 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>
* | Rework the alpm_unpack functionsXavier Chantry2009-10-11
| | | | | | | | | | | | | | Add support to extract a list of entries Signed-off-by: Xavier Chantry <shiningxc@gmail.com> 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>
* | libalpm: clean up lock functionDan McGee2009-10-11
| | | | | | | | | | | | | | We were doing a lot of manual work; leverage the standard library a bit to do more for us. Signed-off-by: Dan McGee <dan@archlinux.org>
* | int typing: s/unsigned short/int/ in libalpmDan McGee2009-10-11
| | | | | | | | | | | | | | | | | | | | After our recent screwup with size_t and ssize_t in the download code, I found the `-Wsign-conversion` flag to GCC to see if we were doing anything else boneheaded. I didn't find anything quite as bad, but we did have some goofups- most of our public unsigned methods would return -1 on error, which is a bit odd in an unsigned context. Signed-off-by: Dan McGee <dan@archlinux.org>
* | libalpm/util.c : remove _alpm_strreplaceXavier Chantry2009-09-06
|/ | | | | | | | | This function is unused since commit 358cc5804a2df873180e6d9ef2420ab3247f8437. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> [Dan: also kill from util.h] Signed-off-by: Dan McGee <dan@archlinux.org>
* Add a missing newline.Xavier Chantry2009-08-03
| | | | | Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Use full path to ldconfigMarc - A. Dahlhaus2009-08-03
| | | | | | | | | | If /sbin is not in the PATH and sudo is used, ldconfig cannot be found. So use /sbin/ldconfig instead. The code checked for the existence of /sbin/ldconfig anyway.. Signed-off-by: Marc - A. Dahlhaus <mad@wol.de> Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Run ldconfig inside chroot.Xavier Chantry2009-07-16
| | | | | | | | | This fixes FS#15294. The code to run a command inside a chroot was refactored from the _alpm_runscriptlet function to _alpm_run_chroot. Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
* Update copyright headers and messagesDan McGee2009-07-01
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* alpm_unpack : change prefix handling to workaround FS#12148.Xavier Chantry2009-01-20
| | | | | | | | | Instead of appending the prefix to each entry name, we can chdir to the prefix before extracting, and restoring when it is done. This seems to work better with the strange and special case of FS#12148 where an archive contained the "./" entry. Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
* Merge branch 'maint'Dan McGee2009-01-18
|\
| * Use archive_entry_set_perm instead of archive_entry_set_modeNagy Gabor2009-01-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes FS#12148 ('unstable' regular file). I also changed the other archive_entry_set_mode usage in add.c to archive_entry_set_perm. Since I cannot find any relevant info in libarchive manual, I quote Tim Kientzle (the author of libarchive) here, and I say thank you for his help. *** Tim Kientzle wrote ************************************* This is the problem in libalpm/util.c: 323 if(S_ISREG(st->st_mode)) { 324 archive_entry_set_mode(entry, 0644); 325 } else if(S_ISDIR(st->st_mode)) { 326 archive_entry_set_mode(entry, 0755); 327 } Your example unstable.db.tar.gz is not empty. It has one entry in it, called "./". That entry is marked as a directory. But, when you call archive_entry_set_mode(), you are changing the file type! archive_read_extract() then creates the file /var/unstable as you requested. (archive_read_extract() will replace an empty directory with a file.) You should either set the mode value correctly: 323 if(S_ISREG(st->st_mode)) { 324 archive_entry_set_mode(entry, IFREG | 0644); 325 } else if(S_ISDIR(st->st_mode)) { 326 archive_entry_set_mode(entry, IFDIR | 0755); 327 } Or use archive_entry_set_perm(), which does not change the file type: 323 if(S_ISREG(st->st_mode)) { 324 archive_entry_set_perm(entry, 0644); 325 } else if(S_ISDIR(st->st_mode)) { 326 archive_entry_set_perm(entry, 0755); 327 } ************************************************************ Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* | Rename alpm_get_md5sum to alpm_compute_md5sum and alpm_dep_get_string to ↵Nagy Gabor2009-01-12
| | | | | | | | | | | | | | | | | | | | | | alpm_dep_compute_string This patch introduces the following function name convention: _compute_ in function name: the return value must be freed. _get_ in function name: the return value must not be freed. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* | libalpm: add PID to db.lckAllan McRae2009-01-03
|/ | | | | | | | | This is the first step in being able to automatically remove phantom lock files. Signed-off-by: Allan McRae <allan@archlinux.org> [Dan: fix compilation warnings] Signed-off-by: Dan McGee <dan@archlinux.org>
* libalpm: handle syscall interruption correctlyDan McGee2008-10-12
| | | | | | | | | | | | | It is possible to throw EINTR from a system call such as open(), close(), or waitpid() if custom signal handlers are set up and they are not initialized with the SA_RESTART flag. This was noticed by Andreas Radke when ^C (SIGINT) was given during the call to waitpid(), causing it to throw the EINTR error and we could not accommodate it. Simply wrap these calls in a simple loop that allows us to retry the call if interrupted. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove an usused variable from alpm/util.c/_alpm_lckmk()Nagy Gabor2008-08-19
| | | | | | | | | | | Probably a tweakable "lockdb-retry" option was planned which is not implemented. (Now it should be implemented in front-end.) So now this variable was unused and caused a small memleak. (FREE(dir) was not reached in case of error.) Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix segfault on x86_64 when using UseSyslogDan McGee2008-08-08
| | | | | | | | | | | | Due to differences in handling va_list between i686 and x86_64, this bug can only be seen on x86_64. va_list usage is not allowed but we had been getting away with it. See http://lists.opensuse.org/opensuse-programming/2008-02/msg00005.html for details and explanation. This fixes FS#11096. Signed-off-by: Dan McGee <dan@archlinux.org>