summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
Commit message (Collapse)AuthorAge
* Update copyright on changed files since beginning of yearDan McGee2012-01-18
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* util.c, rmrf(): only create string when neededOlivier Brunel2012-01-18
| | | | | | | | 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>
* Use isdigit() rather than character range comparisonsDan McGee2012-01-18
| | | | | | This is safer and guaranteed to work with even exotic character sets. Signed-off-by: Dan McGee <dan@archlinux.org>
* Use correct size in memsetDan McGee2011-12-05
| | | | | | | | We were using the size of a pointer, not the size of the whole archive_read_buffer struct. Thanks to Clang/LLVM 3.0 and Allan/Dave in IRC for finding this one. Signed-off-by: Dan McGee <dan@archlinux.org>
* _alpm_ldconfig: return value from _alpm_run_chrootDan McGee2011-11-30
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix thinko in _alpm_strip_newlineDan McGee2011-11-01
| | | | | | | | | The point of this early compare to NULL byte check was so we could bail early and skip the strcmp() call. Given we weren't doing the check right, this never exited early. Fix it to work as intended. Noticed-by: Pepe Juárez <trulustapa@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
* Introduce ALPM_BUFFER_SIZE constantDan McGee2011-10-27
| | | | | | | | | | | | | | This takes the place of three previously used constants: ARCHIVE_DEFAULT_BYTES_PER_BLOCK, BUFFER_SIZE, and CPBUFSIZE. In libarchive 3.0, the first constant will be no more, so we can ensure we are forward-compatible by removing our usage of it now. The rest are unified for consistency. By default, we will use the value of BUFSIZ provided by <stdio.h>, which is 8192 on Linux. If that is undefined, a default value is provided. Signed-off-by: Dan McGee <dan@archlinux.org>
* Parse '0' as a valid package installed sizeDan McGee2011-10-04
| | | | | | This was a bad oversight on my part, pointed out by Jakob. Whoops. Signed-off-by: Dan McGee <dan@archlinux.org>
* Use the full buffer when computing md5/sha256 sumsDan McGee2011-09-28
| | | | | | | | | | | | | | | No wonder these were slower than expected. We were only reading 4 (32-bit) or 8 (64-bit) bytes at a time and feeding it to the hash functions. Define a buffer size constant and use it correctly so we feed 8K at a time into the hashing algorithm. This cut one larger `-Sw --noconfirm` operation, with nothing to actually download so only timing integrity, from 3.3s to 1.7s. This has been broken since the original commit eba521913d6 introducing OpenSSL usage for crypto hash functions. Boy do I feel stupid. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove all usages of alpm_list_getdata() from the libraryDan McGee2011-09-20
| | | | | | No need for the indirection; just access ->data instead. Signed-off-by: Dan McGee <dan@archlinux.org>
* Use more efficient way of restoring working directoryDan McGee2011-09-19
| | | | | | | | | | | | Rather than using a string-based path, we can restore the working directory via a file descriptor and use of fchdir(). From the getcwd manpage: Opening the current directory (".") and calling fchdir(2) to return is usually a faster and more reliable alternative when sufficiently many file descriptors are available. Signed-off-by: Dan McGee <dan@archlinux.org>
* Ensure entire struct is zeroed in _alpm_parsedate()Dan McGee2011-09-18
| | | | | Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
* avoid blowing out the filecache list when using tmpdirDave Reisner2011-09-06
| | | | | | | | | | | | | | | | _alpm_filecache_setup() destroys the list of cachedirs when it finds no writeable directories in the config. This put us in an awkward situation where _alpm_filecache_find() would locate a downloaded file in a r/o cachedir, but then fail to install it after _alpm_filecache_setup() is called (with a NULL argument). Change this behavior to merely prepend the temporary directory to the list of available cachedirs. Dan exposed it in e07547ee4ed4, as now a package can be found in a directory we may not be able to actually store packages in. Reported-by: Rémy Oudompheng <remy@archlinux.org> Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Former transaction callback rename refactorDan McGee2011-09-02
| | | | | | | | | | | | | Put all the callback stuff in alpm.h in one spot, and make the following renames for clarity with the new structure: ALPM_TRANS_EVT_* --> ALPM_EVENT_* ALPM_TRANS_CONV_* --> ALPM_QUESTION_* ALPM_TRANS_PROGRESS_* --> ALPM_PROGRESS_* alpm_option_get_convcb() --> alpm_option_get_questioncb() alpm_option_set_convcb() --> alpm_option_set_questioncb() Signed-off-by: Dan McGee <dan@archlinux.org>
* Move all callbacks up to the handle levelDan McGee2011-09-02
| | | | | | | | | 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>
* _alpm_parsedate(): return time_t and not longDan McGee2011-09-01
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Parse > 2GiB file sizes correctlyDan McGee2011-08-29
| | | | | | | | | | | | | | | | | | | | | | We were using atol(), which on 32 bit, cannot handle values greater than 2GiB, which is fail. Switch to a strtoull() wrapper function tailored toward parsing off_t values. This allows parsing of very large positive integer values. off_t is a signed type, but in our usages, we never parse or have a need for negative values, so the function will return -1 on error. Before: $ pacman -Si flightgear-data | grep Size Download Size : 2097152.00 K Installed Size : 2097152.00 K After: $ ./src/pacman/pacman -Si flightgear-data | grep Size Download Size : 2312592.52 KiB Installed Size : 5402896.00 KiB Signed-off-by: Dan McGee <dan@archlinux.org>
* lib/libalpm/util.c: Fix two memory leaksLukas Fleischer2011-08-28
| | | | | | | | Free "md5sum" if md5_file() fails in alpm_compute_md5sum(). Free "sha256sum" if sha2_file() fails in alpm_compute_sha256sum(). Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> Signed-off-by: Dan McGee <dan@archlinux.org>
* strtrim: don't move empty stringDan McGee2011-08-25
| | | | | | | | | | 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>
* Rework finding a writable cache directoryDan McGee2011-08-19
| | | | | | | | | | | | | | | | | | | | This is a refactor and refresh of the code used to find where we should download packages. * Incorporate suggestions from FS#25435 to use TMPDIR from the environment if set, otherwise fall back to /tmp as before. * Make the writability tests a bit more in depth. We now do a three part check consisting of: - S_ISDIR(): is this even a directory - access(W_OK): is this directory writable by the current user. Unfortunately for root, this almost always returns that it is, but in the case of a RO mount or NFS share inaccessible to root, this check will exclude the directory. - mode & (any write bit): is there a writable bit set on this directory. This makes it possible to enforce a read-only cache directory by setting permissions to 0555, for example. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove usages of alpm_list_next() in backendDan McGee2011-08-18
| | | | | | | Another function call that can be replaced by a single pointer dereference. Signed-off-by: Dan McGee <dan@archlinux.org>
* Validate the sha256sum if availableDan McGee2011-08-15
| | | | | | Adjust load_internal() to check the sha256sum value if we have it. Signed-off-by: Dan McGee <dan@archlinux.org>
* Add ALPM sha256sum routinesDan McGee2011-08-15
| | | | | | These mirror ones we already have for md5sums. Signed-off-by: Dan McGee <dan@archlinux.org>
* Don't walk off front of string when stripping newlineDan McGee2011-08-09
| | | | | | | | If the string was zero-length to begin with, or consists of only newline characters, nothing stopped us from incrementing right off the front of the string. Ensure len stays above zero the whole time. Signed-off-by: Dan McGee <dan@archlinux.org>
* _alpm_access(): don't call gettext() in debug level loggersDan McGee2011-08-08
| | | | | | | | This is standard procedure elsewhere and cuts down on translations that won't be seen (and we don't want if we need English debug output anyway). Signed-off-by: Dan McGee <dan@archlinux.org>
* Don't trim whitespace when reading database entriesDan McGee2011-08-02
| | | | | | | | | | | We don't write with extra or unknown whitespace, so there is little reason for us to trim it when reading either. This also fixes the hopefully never encountered "paths that start or end with spaces" issue, for which two pactests have been added. The tests also contain other evil characters that we have encountered before and handle just fine, but it doesn't hurt to ensure we don't break such support in the future. Signed-off-by: Dan McGee <dan@archlinux.org>
* add _alpm_access() wrapperFlorian Pritz2011-07-18
| | | | | | | | This is a wrapper function for access() which logs some debug information and eases handling in case of split directory and filename. Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Dan McGee <dan@archlinux.org>
* Handle removal of empty directories properlyDan McGee2011-07-18
| | | | | | | | | | | | | | | | | | | | This addresses FS#25141. We shouldn't remove every empty directory we come across during the removal process unless it is truly not known to any other package. This will prevent removal of essential directories such as '/var/lock/'. This is accomplished by first checking the empty/non-empty status of a directory, which was previously done implicitly by calling rmdir() and ignoring errors. We do this to avoid the next (new) check in most cases, which is to look at all local packages to see if the to-be-removed directory is present in another packages' filelist. If we do not find it anywhere, then we remove it, else we keep the file around. The pactest has been updated to test more cases, as well as finding a flaw in the original expected to fail case- we need separate DIR and FILE based EXIST rules. Signed-off-by: Dan McGee <dan@archlinux.org>
* Prefix _alpm_errno_t members with ALPMAllan McRae2011-07-02
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Prefix alpm_transevt_t members with ALPMAllan McRae2011-07-02
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Prefix alpm_loglevel_t members with ALPMAllan McRae2011-07-02
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Merge remote-tracking branch 'allan/breakshit'Dan McGee2011-06-30
|\
| * Rename pmhandle_t to alpm_handle_tAllan McRae2011-06-28
| | | | | | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* | lib/util: modify entry_prefix, not prefixDave Reisner2011-06-30
|/ | | | | | | | | Modifying prefix caused tmp directories to be left behind after running scriptlets, and the path '/' to be passed to _alpm_rmrf. Broken in f01c6f. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix several -Wshadow warningsDan McGee2011-06-27
| | | | | | | | | | Only one of these looked like a real red flag, in find_requiredby(), but it doesn't hurt to fix several of them up anyway. Unfortunately, we can't turn this on universally due to things like the sync(), remove(), etc. builtins which we often use as variable names. Signed-off-by: Dan McGee <dan@archlinux.org>
* Make sync DB reading a bit more flexibleDan McGee2011-06-24
| | | | | | | | | | | We can reorganize things a bit to not require reading a directory-only entry first (or at all). This was noticed while working on some pactest improvements, but should be a good step forward anyway. Also make _alpm_splitname() a bit more generic in where it stores the data it parses. Signed-off-by: Dan McGee <dan@archlinux.org>
* archive_fgets(): ensure we return any trailing text with no newlineDan McGee2011-06-24
| | | | | | | | | | Discovered this when doing some pactest rewrite work to generate archives in memory only. If a sync database file or PKGINFO file is missing a newline on the final line, the text from that line gets tossed aside and never read into the package struct. This is pretty critical when that last line is a depend or something. Signed-off-by: Dan McGee <dan@archlinux.org>
* Clean up util md5sum methodDan McGee2011-06-20
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Switch all logging to use handle directlyDan McGee2011-06-13
| | | | | | | This is the last user of our global handle object. Once again the diff is large but the functional changes are not. Signed-off-by: Dan McGee <dan@archlinux.org>
* Move pm_errno onto the handleDan McGee2011-06-13
| | | | | | This involves some serious changes and a very messy diff, unfortunately. 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>
* Require handle argument to alpm_logaction()Dan McGee2011-06-09
| | | | | | | This is the first in a series of patches to update the API to remove the implicit global handle variable. Signed-off-by: Dan McGee <dan@archlinux.org>
* _alpm_lstat: only duplicate string if necessaryDan McGee2011-06-09
| | | | | | | | | The vast majority of the time we will just be passing the same string value on to the lstat() call. The only time we need to duplicate it is if the path ends in '/'. In one run using a profiler, only 400 of the 200,000 calls (0.2%) required the string to be copied first. Signed-off-by: Dan McGee <dan@archlinux.org>
* Add helper methods for setting directory optionsDan McGee2011-06-07
| | | | | | | This keeps duplicate code to a minimum. This will come in more handy as we refactor some of these option setters away. Signed-off-by: Dan McGee <dan@archlinux.org>
* Use standard errno codes in return from _alpm_archive_fgetsDan McGee2011-06-03
| | | | | | | | | | | | | This allows us to not require the context (e.g. handle) when calling this function. Also beef up the checks in the two callers of this function to bail if the last return code is not ARCHIVE_EOF, which is the expected value. This requires a change to one of the pactest return codes and the overall result of the test, but results in a much safer operating condition whereby invalid database entries will stop the operation. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove global handle from util.cDan McGee2011-06-03
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Push down extern handle variable to files that need itDan McGee2011-06-03
| | | | | | | This will make the patching process less invasive as we start to remove this variable from all source files. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove ALPM_LOG_FUNC macroDan McGee2011-06-03
| | | | | | | | | The usefulness of this is rather limited due to it not being compiled into production builds. When you do choose to see the output, it is often overwhelming and not helpful. The best bet is to use a debugger and/or well-placed fprintf() statements. 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>