Commit Graph

255 Commits

Author SHA1 Message Date
Andrew Gregory 9bfd6ff275 restrict transaction package origins
This moves the "wrong args" error up from trans_commit to add_pkg when
used with a local pkg and adds the error for remove_pkg when used with
a sync pkg, which currently just removes the db entry.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-03 11:25:54 +10:00
Olivier Brunel 28dbd5551e Update the event callback
Instead of using two void* arguments for all events, we now send one
pointer to an alpm_event_t struct. This contains the type of event that
was triggered.

With this information, the pointer can then be typecasted to the
event-specific struct in order to get additional arguments.

Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-03 11:25:54 +10:00
Andrew Gregory b9601b1e59 alpm: export *_free functions
Front-ends should be able to free memory that alpm hands them.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-02-04 13:48:37 +10:00
Florian Pritz cd2370754a Remove ts and sw from vim modeline when noet is set
Forcing vim users to view files with a tabstop of 2 seems really
unnecessary when noet is set. I find it much easier to read code with
ts=4 and I dislike having to override the modeline by hand.

Command run:
find . -type f -exec sed -i '/vim.* noet/s# ts=2 sw=2##' {} +

Signed-off-by: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-28 20:19:25 +10:00
Olivier Brunel 4e9d88aa05 Rename ALPM_EVENT_OPTDEP_REQUIRED to _OPTDEP_REMOVAL
Because this event is triggered when an optdepend for another package is
being removed.

Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-28 20:10:49 +10:00
Allan McRae 3bb3b1555a Update copyright years for 2014
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06 14:38:50 +10:00
Andrew Gregory 2f8be5f8db trans_prepare: always sort trans->remove by deps
Packages can be removed during a sync transaction either directly or
due to conflicts and need to be sorted.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-12-19 15:19:52 +10:00
Jason St. John 230bd5c2fd Fix whitespace and other formatting issues
This commit:
-- replaces space-based indents with tabs per the coding standards
-- removes extraneous whitespace (e.g. extra spaces between function args)
-- adds missing braces for a one-line if statement

Signed-off-by: Jason St. John <jstjohn@purdue.edu>
2013-11-15 11:02:27 +10:00
Andrew Gregory d78f45ae0c log important events from the backend
This ensures that important events will be logged and consistent
regardless of the frontend.  The need for global context in the event
callback is also removed.  The event is logged before any post_* scripts
run, so this also moves the post_* script output underneath the event in
the log.

Fixes FS#36504

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-11-15 11:02:27 +10:00
Andrew Gregory c3493360af deps.c: pass alpm_list** to _alpm_recursedeps
Improves consistency and makes it clear that targs will be modified by
_alpm_recursedeps.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-10-31 16:20:03 +10:00
Andrew Gregory c2134fde2b sortbydeps: include local pkgs in dep graph
Detecting indirect dependencies by traversing a package's entire
dependency tree is prohibitively slow for larger transactions.  Instead
add local packages to the dependency graph.  This additionally requires
delaying dependency ordering for sync operations so that removed
packages may be excluded from dependency detection.

tests/sync012.py was also updated to ensure that the dependency cycle
was actually detected.

Fixes FS#37380

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-10-31 16:20:02 +10:00
Andrew Gregory 897e2b121a use full path when checking for mountpoints
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-07-05 14:34:58 +10:00
Andrew Gregory b1e495b88d unlink_file: treat symlinks like normal files
We always want to work with the package file itself, not its target if
it's a symlink.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-06-03 13:33:47 +10:00
Andrew Gregory 5cfa4ec47e alpm_filelist: remove resolved_path
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-06-03 13:33:47 +10:00
Andrew Gregory d35a7fb6f3 alpm/remove.c: add newlines to debug output
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-14 11:47:11 +10:00
Allan McRae e6b8d5189f Do not resolve every local package filelist on remove
Although technically correct, this results in my system taking ~30 seconds
to resolve all filelists when removing a package that has a directory not
owned by any package.  The check for if any package own the empty directory
is a rare enough occurance, and it will be even rarer when that directory
has a directory symlink in its path, so just revert this at this stage.

Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07 15:38:47 +10:00
Andrew Gregory 19754b34a3 use resolved_path for filelist_contains
alpm_filelist_contains was being used to search for resolved paths, but
searching in the unresolved paths, causing it to miss matches.  We
always search unresolved paths and search the resolved paths if
available because _alpm_filelist_resolve is not public and requires
a context handle, so it can't be called from alpm_filelist_contains.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-02-24 13:11:54 +10:00
Dave Reisner 26a79cb29d libalpm: never attempt to remove a mountpoint
Arch Linux typically runs into this with /sys when upgrading the
filesystem package in build chroots, but LXC users might also run into
this, since their /sys is shared from the host and must, for security
reasons, be mounted RO.

I've neglected to add any tests for this because they would require root
in order to run. Current tests all pass with this patch and I've
confirmed the desired behavior in a VM. Incidentally, the first hunk of
this patch (skipping can_remove_file checks for directories) resolves the
case of API mountpoints being removed since they eventually fall into
unlink_file and fail with "contains files". However, this patch should
still be the Right Thing To Do™, as we can't possibly remove a directory
that is also a mountpoint.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>

[Allan] Do not skip checking if directories can be removed. Instead test
if directories are mountpoints in can_remove_file.

Signed-off-by: Allan McRae <allan@archlinux.org>
2013-02-16 11:06:43 +10:00
Andrew Gregory 66a9b53141 add caller prefix to alpm_logaction
prefix defaults to "UNKOWN" if null or an empty string is provided.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-28 23:38:46 +10:00
Pang Yan Han b6320de4be Save backup files with extension .pacsave.n
Teach pacman to save backup files with extension .pacsave.n, where n is a
positive integer. The current backup file shall be saved as <name>.pacsave,
while existing .pacsave.n files will be renamed to <name>.pacsave.n+1

Example:
1. You have subversion installed in your local repo. /etc/conf.d/svnserve
   is a file to be backed up. It contains local modifications

2. You remove subversion from your repo. /etc/conf.d/svnserve is backed up as
   /etc/conf.d/svnserve.pacsave

2. You install subversion again

3. You edit /etc/conf.d/svnserve

4. You remove subversion. The existing /etc/conf.d/svnserve.pacsave is renamed
   to /etc/conf.d/svnserve.pacsave.1 and /etc/conf.d/svnserve is backed up as
   /etc/conf.d/svnserve.pacsave

Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>

Rebased from original email and adjusted for util-common usage.
Signed-off-by: Florian Pritz <bluewind@xinu.at>

Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04 21:49:37 +10:00
Allan McRae 1dd3405813 Update copyright year for 2013
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-03 12:03:09 +10:00
Allan McRae 62f1c590fc Make alpm_pkg_find public
This function is particularly useful, so make it public.

Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14 12:35:34 +10:00
Allan McRae eb9e74ecc7 Notify of removed package required as optdepend
When a package is being removed, provide a notification (via a callback)
if any local package requires it as an optdepend.

Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14 12:35:34 +10:00
Allan McRae e32d129967 Remove incorrect documentation for unlink_file
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-09-18 08:29:55 -05:00
Dan McGee 72d3713cc7 Move filelist functions into separate source file
We have a few of these and might as well gather them together. This also
cleans up the code a bit by using an enum instead of integer values, as
well as makes a "search for file in filelist" function public so
frontends can do better than straight linear search of the filelists.

Signed-off-by: Dan McGee <dan@archlinux.org>
2012-08-02 09:39:08 -05:00
Andrew Gregory ac990b96e7 libalpm/remove.c - add doxygen
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-05-21 00:03:20 -05:00
Dan McGee e50c4a8837 Merge branch 'maint'
Conflicts:
	lib/libalpm/diskspace.c
	src/pacman/util.h
2012-01-23 12:20:52 -06:00
Dan McGee 562109c0e8 Update copyright on changed files since beginning of year
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-18 22:25:27 -06:00
Dan McGee 4f02b98338 Merge branch 'maint'
Conflicts:
	lib/libalpm/signing.c

Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-08 12:14:04 -06:00
Dan McGee a1437cbf1b Remove useless logger message
We don't need two log messages back-to-back about the same thing here.

Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-05 16:48:21 -06:00
Dan McGee eb5cb8ec02 Remove unnecessary counters in file removal code
Now that filelist arrays know their own size, we don't need to do the
bookkeeping we used to do when they were linked lists. Remove some of
the counter variables and use math instead.

Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-02 12:58:51 -06:00
Dan McGee 6b29374a60 Rework package removal code
Extract the actual unlinking of files into a new method, which
eliminates a goto used for flow control. Also fix up a few small issues
in the code:

* Unnecessary (unsigned long) cast, use '%zd' instead
* Total up errors returned from unlink_file calls and return to caller
* Be consistent with scriptlets- we run pre_remove on dbonly, so we
  should also run post_remove. Both can be disabled by way of the
  --noscriptlet argument.
* Don't pass an invalid pointer to oldpkg to the event callbacks;
  instead call the callback before we free the object.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-23 14:37:03 -06:00
Dave Reisner d6ccd44390 include config.h via Makefiles
Ensures that config.h is always ordered correctly (first) in the
includes. Also means that new source files get this for free without
having to remember to add it.

We opt for -imacros over -include as its more portable, and the
added constraint by -imacros doesn't bother us for config.h.

This also touches the HACKING file to remove the explicit mention of
config.h as part of the includes.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-21 18:13:17 -06:00
Dave Reisner 902305f163 add support for back end fnmatch'd options
This is work originally provided by Sascha Kruse on FS#20360 with only
minor adjustments to the implementation. It's been expanded to cover:
NoUpgrade, NoExtract, IgnorePkg, IgnoreGroup.

Adds tests ignore008, sync139, sync502, and sync503.

Also satisfies FS#18988.

Original-work-by: Sascha Kruse <knopwob@googlemail.com>
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-11-13 14:19:00 -05:00
Dan McGee ae25167bcd Large performance improvement for check for owned directories
We can take a large shortcut here that saves us a lot of time,
especially when upgrading packages with lots of directories. Obviously
iterating the full file list of every single package to determine if
this directory was present in any other package can take quite some time
on a system with many packages installed. We don't need to remove a
directory at all if we are upgrading a package and the version we are
moving to still had the directory.

Also make a small optimization on the package comparsion- we really only
care about equality here, not the result of the compare, so we can
shortcut using our name_hash.

What kind of benefit does this give us? Oh, only a reduction from 295.7
million to 1.4 million strcmp() calls (99.5% fewer) during a
`pacman -S linux libreoffice-common` operation.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-14 14:58:12 -05:00
Dan McGee 39b0ac43fc Revamp scriptlet path formation for scriptlets in local database
Expose the current static get_pkgpath() function internally to the rest
of the library as _alpm_local_db_pkgpath(). This allows use of this
convenience function in add.c and remove.c when forming the path to the
scriptlet location.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-30 10:55:58 -05:00
Dan McGee 73139ccb3c Refactor _alpm_runscriptlet()
Add an is_archive parameter to reduce the amount of black magic going
on. Rework to use fewer PATH_MAX sized local variables, and simplify
some of the logic where appropriate in both this function and in the
callers where duplicate calls can be replaced by some conditional
parameter code.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-30 10:55:58 -05:00
Dan McGee 6e081a0c57 Move pacsave path construction code off the stack
This is definitely not in the normal hot path, so we can afford to do
some temporary heap allocation here.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-28 04:48:53 -05:00
Dan McGee e1899cbc64 Be smarter about running ldconfig during removal transactions
1. Don't run it if something failed in package removal- this mirrors
what we already do in sync transactions.
2. Don't run it if we are invoking it for the replaces removal bit of a
sync transaction- it doesn't make sense to run ldconfig halfway through
a sync install; we should only run it once at the end.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-19 13:18:42 -05:00
Dan McGee a94ad29740 Search for non-prefixed paths in skip_remove list
We add them to this list with the root path not appended; we should be
searching for them this way as well.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-09-19 13:17:16 -05:00
Dan McGee 98fdfa1968 Former transaction callback rename refactor
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-02 21:45:08 -05:00
Dan McGee 37da18aee8 Move all callbacks up to the handle level
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-09-02 21:45:03 -05:00
Dan McGee 6d544984f2 Be more robust when copying package data
This changes the signature of _alpm_pkg_dup() to return an integer error
code and provide the new package in a passed pointer argument. All
callers are now more robust with checking the return value of this
function to ensure a fatal error did not occur.

We allow load failures to proceed as otherwise we have a chicken and egg
problem- if a 'desc' local database entry is missing, the best way of
restoring said file is `pacman -Sf --dbonly packagename`. This patch
fixes a segfault that was occurring in this case.

Fixes the segfault reported in FS#25667.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-19 11:09:57 -05:00
Dan McGee c4bd476ad1 Remove use of no-op accessor functions in library
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-18 10:47:41 -05:00
Dan McGee 1f6afe6b0b Dependency code style cleanups
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-11 11:18:55 -05:00
Dan McGee 07a1292721 Check return value of rename() calls
We did a good job checking this in add.c, but not necessarily anywhere
else. Fix this up by adding checks into dload.c, remove.c, and conf.c in
the frontend. Also add loggers where appropriate and make the message
syntax more consistent.

Signed-off-by: Dan McGee <dan@archlinux.org>
2011-08-08 13:29:45 -05:00
Dan McGee bb3dada871 Convert package filelists to an array instead of linked list
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-21 15:04:30 -05:00
Florian Pritz dad96ccce2 replace access() calls for debug info where applicable
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-18 10:44:28 -05:00
Dan McGee 1c39e4fbad Handle removal of empty directories properly
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>
2011-07-18 10:34:05 -05:00
Dan McGee af357d6ab0 Allow fileconflict if unowned file moving into backup array
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-14 15:34:04 -05:00