summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/conflict.c
AgeCommit message (Collapse)AuthorFilesLines
2011-12-12lib/conflict: save strlen call by reusing snprintf returnDave Reisner1-2/+3
The return should probably be checked to ensure its not longer than PATH_MAX, but I have no idea what the correct behavior is when that happens. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-11-01Merge branch 'maint'Dan McGee1-14/+19
2011-10-27Fix issues with replacing unowned symlinksDan McGee1-14/+19
There aretwo seperate issues in the same block of file conflict checking code here: 1) If realpath errored, such as when a symlink was broken, we would call 'continue' rather than simply exit this particular method of resolution. This was likely just a copy-paste mistake as the previous resolving steps all use loops where continue makes sense. Refactor the check so we only proceed if realpath is successful, and continue with the rest of the checks either way. 2) The real problem this code was trying to solve was canonicalizing path component (e.g., directory) symlinks. The final component, if not a directory, should not be handled at all in this loop. Add a !S_ISLNK() condition to the loop so we only call this for real files. There are few other small cleanups to the debug messages that I made while debugging this problem- we don't need to keep printing the file name, and ensure every block that sets resolved_conflict to true prints a debug message so we know how it was resolved. This fixes the expected failures from symlink010.py and symlink011.py, while still ensuring the fix for fileconflict007.py works. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-14Make _alpm_filelist_contains() NULL-safeDan McGee1-3/+7
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-27Ensure fileconflict value is actually a stringDan McGee1-16/+14
When we switched to a file object and not just a simple string, we missed an update along the way here in target-target conflicts. This patch looks large, but it really comes down to one errant (char *) cast before that has been reworked to explicitly point to the alpm_file_t object. The rest is simply code cleanup. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-03Former transaction callback rename refactorDan McGee1-2/+2
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>
2011-09-03Move all callbacks up to the handle levelDan McGee1-3/+2
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-30Remove outdated comment for _alpm_outerconflictsAllan McRae1-4/+1
Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-18Remove use of no-op accessor functions in libraryDan McGee1-3/+2
The functions alpm_db_get_name(), alpm_pkg_get_name(), and alpm_pkg_get_version() are not necessary at all, so remove the calling and indirection when used in the backend, which makes things slightly more efficient and reduces code size. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-15Parse conflicts/provides/replaces at database load timeDan McGee1-11/+10
We did this with depends way back in commit c244cfecf654d3 in 2007. We can do it with these fields as well. Of note is the inclusion of provides even though only '=' is supported- we'll parse other things, but no guarantees are given as to behavior, which is more or less similar to before since we only looked for the equals sign. Also of note is the non-inclusion of optdepends; this will likely be resolved down the road. The biggest benefactors of this change will be the resolving code that formerly had to parse and reparse several of these fields; it only happens once now at load time. This does lead to the disadvantage that we will now always be parsing this information up front even if we never need it in the split form, but as these are uncommon fields and our parser is quite efficient it shouldn't be a big concern. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-09Conflict comparison performance enhancementsDan McGee1-17/+17
* Add *_hash fields to conflict struct and populate them * Remove unnecessary backwards string comparisons Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-21Convert package filelists to an array instead of linked listDan McGee1-29/+36
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>
2011-07-14Allow fileconflict if unowned file moving into backup arrayDan McGee1-0/+16
The bulk of this commit is adding new tests to ensure the new behavior works without disrupting old behavior. This is a relatively sane maneuver when a package adds a conf file (e.g. '/etc/mercurial/hgrc') that was not previously in the package, but it is placed in the backup array. In essence, we can treat the existing file as having always been a part of the package and do our normal compare/install as pacnew logic checks. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-03Merge remote-tracking branch 'allan/ALPM'Dan McGee1-21/+21
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
2011-07-03conflict code tweaks and cleanupsDan McGee1-20/+14
We can take advantage of a few things on our new and improved filelist in this code. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-03Move alpm filelists to a struct objectDan McGee1-16/+39
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>
2011-07-01Prefix _alpm_errno_t members with ALPMAllan McRae1-3/+3
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-07-01Prefix alpm_transprog_t members with ALPMAllan McRae1-2/+2
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-07-01Prefix alpm_loglevel_t members with ALPMAllan McRae1-13/+13
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-07-01Prefix alpm_fileconflicttype_t members with ALPMAllan McRae1-3/+3
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-30Fix a few warnings pointed out via clang scan-buildDan McGee1-1/+1
Some of these are legit (the backup hash NULL checks), while others are either extemely unlikely or just impossible for the static code analysis to prove, but are worth adding anyway because they have little overhead. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-28Rename pmfileconflict_t to alpm_fileconflict_tAllan McRae1-4/+4
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmconflict_t to alpm_conflict_tAllan McRae1-11/+11
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmdepend_t to alpm_depend_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmtrans_t to alpm_trans_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmpkg_t to alpm_pkg_tAllan McRae1-6/+6
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmdb_t to alpm_db_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmhandle_t to alpm_handle_tAllan McRae1-6/+6
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-28Rename pmfileconflicttype_t to alpm_fileconflicttype_tAllan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2011-06-27Merge branch 'maint'Dan McGee1-13/+22
Conflicts: lib/libalpm/conflict.c
2011-06-27Ensure a file can be replaced by a directoryDan McGee1-8/+18
This addresses FS#24904. In a normal upgrade case, this replacement seems to work just fine. However, when doing a sync "replace" type upgrade, we weren't properly handling this edge case due to path comparison not ignoring trailing slashes. Fix this by pruning any trailing slashes past a certain point of file conflict resolution where we no longer need them, which allows us to safely detect cases such as now tested in the new pactest. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-27File conflict code cleanupsDan McGee1-11/+11
While researching the root cause of FS#24904, I couldn't help but clean up some of the cruft in here. A few whitespace/line-wrapping issues, but also fix shadowed variables and add some const where applicable. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-16Make struct pmconflict_t publicDan McGee1-18/+0
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-16Make pmfileconflict_t type publicDan McGee1-24/+0
This removes the need to write accessor methods for every type we have, and simplifies the API. Any type that doesn't need magic* can be converted in this fashion to make it easier for frontend applications to use, as well as make it less of a pain to introduce new such structs in the future. * "magic" meaning something like pmpkg_t where values can be lazy loaded. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-14Ensure handle is valid and pm_errno is reset when calling into APIDan McGee1-0/+1
We didn't do due diligence before and ensure prior pm_errno values weren't influencing what happened in further ALPM calls. I observed one case of early setup code setting pm_errno to PM_ERR_WRONG_ARGS and that flag persisting the entire time we were calling library code. Add a new CHECK_HANDLE() macro that does two things: 1) ensures the handle variable passed to it is non-NULL and 2) clears any existing pm_errno flag set on the handle. This macro can replace many places we used the ASSERT(handle != NULL, ...) pattern before. Several other other places only need a simple 'set to zero' of the pm_errno field. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-14Conflict check and skip_remove code cleanupsDan McGee1-34/+50
* Move several variables into better scope * const-ify a few variables * Avoid duplicating filelists if it is unnecessary * Better handling out out of memory condition when adding file conflicts to our list Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-14Switch all logging to use handle directlyDan McGee1-32/+38
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>
2011-06-14Move pm_errno onto the handleDan McGee1-32/+33
This involves some serious changes and a very messy diff, unfortunately. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-14Require handle for alpm_checkconflicts()Dan McGee1-8/+12
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-09Kill all remaining 'PATH_MAX + 1' usagesDan McGee1-3/+3
The few remaining instances were utilized for buffers in calls to snprintf() and realpath(). Both of these functions will always ensure the returned value is padded with '\0', so there is no need for the extra byte. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-03Remove global handle dependencies from sync/upgrade pathsDan McGee1-9/+7
This kills a lot more global handle business off. sync.c still requires the handle declaration for one reference that can't be changed yet; it will be removed in a future patch which isolates all of the necesary API changes. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-03Push down extern handle variable to files that need itDan McGee1-0/+3
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>
2011-06-03Remove unnecessary handle != NULL assertsDan McGee1-7/+0
These are simple accessor functions for a struct; the handle never even comes into play when calling these functions. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-06-03Remove ALPM_LOG_FUNC macroDan McGee1-24/+0
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>
2011-05-04Fix warnings reported by -Wwrite-stringsDan McGee1-5/+3
These are places where we stuck a string constant in a variable not marked as const. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-03-31Unify filelist operation functions in conflict checkingDan McGee1-51/+25
We had two functions that were oh so similar but slightly different. We can combine them and add some conditional operation stuff to decide what to return. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-03-21Style change: return(x) --> return xDan McGee1-31/+31
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>
2011-02-25alpm: alpm_db_get_pkgcache_list => alpm_db_get_pkgcacheDave Reisner1-1/+1
This avoids needless breakage of the public API. Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-17Conflict checking code cleanupDan McGee1-30/+13
* Make conflict_isin() static; it is used nowhere else. * Remove does_conflict(): it turns out to be replaceable by a single call to _alpm_depcmp(). By pushing it up, we can reduce calls to _alpm_splitdep() from 60,368 to 16,940 during one test -Su operation I ran. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-11Fix fileconflict progress with only one packageDan McGee1-2/+4
Signed-off-by: Dan McGee <dan@archlinux.org>