summaryrefslogtreecommitdiff
path: root/lib/libalpm/diskspace.c
Commit message (Collapse)AuthorAge
* diskspace: ensure we match only full path componentsDan McGee2012-02-19
| | | | | | | | | If one had a mountpoint at '/e' (don't ask), a file being installed to '/etc' would map to it incorrectly. Ensure we do more than just prefix matching on paths by doing some more sanity checks once the simple strncmp() call succeeds. Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix sys/mnttab.h header includeDan McGee2012-01-23
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* Add diskspace checking support for Solaris/IllumosDan McGee2012-01-19
| | | | | | | | | Was able to get my hands on one of these boxes today, so add yet another new way of doing this. I'm glad these calls are so standardized. This was compile tested on Linux and Illumos and seems to still be working in both places. Signed-off-by: Dan McGee <dan@archlinux.org>
* diskspace: fix memory leak on root mount not foundDave Reisner2011-09-08
| | | | | Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Use more correct integer types in diskspace checksDan McGee2011-09-07
| | | | | | | | | | | | | | | | This adjusts type usage to match POSIX provided types from <sys/types.h> rather than assuming everything will fit in a long or unsigned long. Use fsblkcnt_t (unsigned) and blkcnt_t (signed) as appropriate. These are affected the same way off_t is on 32 bit platforms, where the types are extende to 64 bits if large file support is enabled. Because most numbers here are block counts, this isn't near as pressing as using a 32-bit variable for file sizes where anything over 2GiB can burn you; we likely can support files at least 512 but mainly 4096 times larger. 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>
* Remove alpm_option_get_* usage from backendDan McGee2011-08-19
| | | | | | These are all available directly on the handle without indirection. 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>
* libalpm: fix a remaining old syntax of RET_ERR() macroRémy Oudompheng2011-08-15
| | | | | | | | It would prevent compilation of pacman on FreeBSD, and possibly other systems. Signed-off-by: Rémy Oudompheng <remy@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Convert package filelists to an array instead of linked listDan McGee2011-07-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This accomplishes quite a few things with one rather invasive change. 1. Iteration is much more performant, due to a reduction in pointer chasing and linear item access. 2. Data structures are smaller- we no longer have the overhead of the linked list as the file struts are now laid out consecutively in memory. 3. Memory allocation has been massively reworked. Before, we would allocate three different pieces of memory per file item- the list struct, the file struct, and the copied filename. What this resulted in was massive fragmentation of memory when loading filelists since the memory allocator had to leave holes all over the place. The new situation here now removes the need for any list item allocation; allocates the file structs in contiguous memory (and reallocs as necessary), leaving only the strings as individually allocated. Tests using valgrind (massif) show some pretty significant memory reductions on the worst case `pacman -Ql > /dev/null` (366387 files on my machine): Before: Peak heap: 54,416,024 B Useful heap: 36,840,692 B Extra heap: 17,575,332 B After: Peak heap: 38,004,352 B Useful heap: 28,101,347 B Extra heap: 9,903,005 B Several small helper methods have been introduced, including a list to array conversion helper as well as a filelist merge sort that works directly on arrays. Signed-off-by: Dan McGee <dan@archlinux.org>
* Merge remote-tracking branch 'allan/ALPM'Dan McGee2011-07-03
|\ | | | | | | | | | | | | | | | | | | Conflicts: lib/libalpm/be_local.c lib/libalpm/be_package.c lib/libalpm/conflict.c lib/libalpm/diskspace.c lib/libalpm/dload.c lib/libalpm/remove.c
| * Prefix _alpm_errno_t members with ALPMAllan McRae2011-07-02
| | | | | | | | Signed-off-by: Allan McRae <allan@archlinux.org>
| * Prefix alpm_transprog_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>
* | diskspace: remove all libarchive usageDan McGee2011-07-03
| | | | | | | | | | | | | | | | Now that the filelists capture mode and size information, we can read the data from there and prevent having to loop through and uncompress every archive to check required diskspace usage. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Move alpm filelists to a struct objectDan McGee2011-07-03
|/ | | | | | | | This allows us to capture size and mode data when building filelists from package files. Future patches will take advantage of this newly available information, and frontends can use it as well. Signed-off-by: Dan McGee <dan@archlinux.org>
* Rename pmtrans_t to alpm_trans_tAllan McRae2011-06-28
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Rename pmpkg_t to alpm_pkg_tAllan McRae2011-06-28
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Rename pmhandle_t to alpm_handle_tAllan McRae2011-06-28
| | | | Signed-off-by: Allan McRae <allan@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>
* 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>
* Remove global handle from diskspace.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>
* 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>
* Merge branch 'maint'Dan McGee2011-04-15
|\ | | | | | | | | | | | | | | Conflicts: lib/libalpm/alpm.h lib/libalpm/trans.c Signed-off-by: Dan McGee <dan@archlinux.org>
| * diskspace: add the actually used statfs type in ifdefsRémy Oudompheng2011-04-06
| | | | | | | | | | | | | | | | | | | | Some systems, like FreeBSD might define both statfs and statvfs: however if statvfs exists whereas getmntinfo() uses a statfs struct, the current ifdefs would select the wrong line of code. Signed-off-by: Rémy Oudompheng <remy@archlinux.org> 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>
* Ensure we have a root partition when checking spaceDan McGee2011-03-17
| | | | | | | | | Partially addresses the "why doesn't CheckSpace work in a chroot" issue. We can't make it work, but we can at least detect when it won't work by checking for a partition for our given installation root. If we can't determine the mountpoint for this, bail out with an error. Signed-off-by: Dan McGee <dan@archlinux.org>
* Add missing newline to warning messageAllan McRae2011-03-16
| | | | | Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* libalpm/diskspace.c: remove bogus parenthesisXavier Chantry2011-03-01
| | | | Signed-off-by: Dan McGee <dan@archlinux.org>
* diskspace: allow used flag to be toggled for both remove and installDan McGee2011-02-11
| | | | | | | | | | | | | | Turn it into an enum rather than a boolean, and use a bitmask like we do for reading DB entries. The relevant flag is turned on in our two calculate loops, and anything reading the used flag later can decided which flag (or either) is relevant. This will allow the read-only partition code to be triggered on a remove-only operation, e.g. if /boot was read-only and one tried to remove grub in a sync transaction. Of course, right now, we don't actually run the diskspace check code in the '-R' codepath. Signed-off-by: Dan McGee <dan@archlinux.org>
* Check mountpoint read-only status when checking spaceDan McGee2011-02-11
| | | | | | | | | | | This is a bit of a stopgap solution for the problem, but an easier one than revamping the file conflict checking code to support the same stuff. Using some more gross autoconf magic, figure out which struct field we need to look at to determine read-only status and store that on our mountpoint struct. If we find out we needed this partition after calculating size requirements, then toss an error. Signed-off-by: Dan McGee <dan@archlinux.org>
* diskspace: use calloc instead of mallocDan McGee2011-02-11
| | | | | | Prevents us from having to manually zero out several of our fields. Signed-off-by: Dan McGee <dan@archlinux.org>
* Fix mount dir length calculationDan McGee2011-02-11
| | | | | | | | | In the getmntinfo() section, the local variable mnt doesn't exist; this would have caused a compile error if I had tested the code on such a platform. Unify both codepaths to just run strlen() on the already copied mount path instead. Signed-off-by: Dan McGee <dan@archlinux.org>
* Skip diskspace checking for symlinks and directories in all casesDan McGee2011-02-08
| | | | | | | | | | | | | | | | | | We did this in some but not all cases, assuming the 0 value coming out of libarchive would not be a problem. However, this does not work for "fake" filesystems such as rpc_pipefs, which reports a free block and total block count of zero. Fix this by not ever counting symlinks or directories, and adding a note explaining that if we someday do count directories, their size needs to be attributed to the proper place. This patch also includes a few cleanups/performance tweaks- avoid calling strlen() on the mountpoint directory string as much by storing this size in our mountpoint struct, and push the snprintf() call up to the calculate functions since we were already doing it here in the remove case. Signed-off-by: Dan McGee <dan@archlinux.org>
* Call archive_read_data_skip() while checking diskspaceDan McGee2011-01-11
| | | | | | | libarchive eventually calls it anyway, but backtraces make a lot more sense if we call it, as well as matching our precedent from alpm_pkg_load(). Signed-off-by: Dan McGee <dan@archlinux.org>
* Add error message stating which partition is fullDan McGee2011-01-11
| | | | | | | | | This is helpful anyway to the user, and should also be helpful to us if we see problems cropping up in the check during development. Also add a missing ->used = 0 initialization in the code path less taken. Signed-off-by: Dan McGee <dan@archlinux.org>
* Ensure we use local package when calculating removed sizeDan McGee2011-01-10
| | | | | | | | | | | We were checking if a package existed locally, but then using the incoming package to calculate removed size rather than the currently installed package. Also adjust the local variable in the replaces loop to make it more clear that we are always dealing with local packages here. Signed-off-by: Dan McGee <dan@archlinux.org>
* Remove need for floating point division in backendDan McGee2011-01-10
| | | | | | | | | | | All of these can be done with integer division; the only slightly interesting part is ensuring we round up like before with calling the ceil() function. We can also remove the math library from requirements; now that the only ceil() calls are gone, we don't need this anymore. 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>
* Use size_t for alpm_list sizesAllan McRae2011-01-07
| | | | | | | | | | | | | There is a lot of swtiching between size_t and int for alpm_list sizes in the codebase. Start converting these to all be size_t by adjusting the return type of alpm_list_count and fixing all additional warnings given by -Wconversion that are generated by this change. Dan: a few more small changes to ensure things compile, adjusting some printf format string characters to accommodate the larger size on x86_64. Signed-off-by: Allan McRae <allan@archlinux.org> 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>
* Only check diskspace availability if needs more than zeroAllan McRae2010-12-20
| | | | | | | | | | The amount of diskspace needed for a transaction can be less than zero. Only test this against the available disk space if it is positive, which avoids a comparison being made between signed and unsigned types (-Wsign-compare). Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
* Add a cushion for diskspace checkingDan McGee2010-12-15
| | | | | | It is the minimum of 5% of disk capacity or 20 MiB on a per-partition basis. Signed-off-by: Dan McGee <dan@archlinux.org>
* diskspace style cleanups and small fixesDan McGee2010-12-12
| | | | | | | | | | | | | | | | * Use our normal return() function syntax * Rework a few things to reduce number of casts * Fix void function argument declaration * Add missing gettext _() call * Remove need for seperate malloc() of statvfs/statfs structure * Unify argument order of static functions- mountpoints now always passed first * Count all files that start with '.' in a package against the DB * Rename db to db_local in check_diskspace to clarify some code * Fix some line wrapping to respect 80 characters Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
* Refactor statfs/statvfs type checkDan McGee2010-12-12
| | | | | | | | | | | Turn it into a configure-type typedef, which allows us to reduce the amount of duplicated code and clean up some #ifdef magic in the code itself. Adjust some of the other defined checks to look at the headers available rather than trying to pull in the right ones based on configure checks. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
* Display progress bar for disk space checkingAllan McRae2010-12-12
| | | | | | | | Checking disk space needed for a transaction can take a while so add an informative progress bar. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>