Commit Graph

106 Commits

Author SHA1 Message Date
Xavier Chantry eab9684837 alpm_unpack : change prefix handling to workaround FS#12148.
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>
2009-01-20 14:03:46 +01:00
Dan McGee c794661f1e Merge branch 'maint' 2009-01-18 13:48:48 -06:00
Nagy Gabor 472e51b975 Use archive_entry_set_perm instead of archive_entry_set_mode
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>
2009-01-18 13:35:17 -06:00
Nagy Gabor 4da70d800a Rename alpm_get_md5sum to alpm_compute_md5sum and alpm_dep_get_string to 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>
2009-01-12 23:59:30 -06:00
Allan McRae b55f478042 libalpm: add PID to db.lck
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>
2009-01-03 00:00:19 -06:00
Dan McGee f9be2334f7 libalpm: handle syscall interruption correctly
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>
2008-10-12 21:28:05 -05:00
Nagy Gabor 729651a554 Remove an usused variable from alpm/util.c/_alpm_lckmk()
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>
2008-08-19 18:43:46 -05:00
Dan McGee d8f8a12665 Fix segfault on x86_64 when using UseSyslog
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>
2008-08-08 22:18:00 -05:00
Dan McGee e6fb229534 Remove unused strverscmp substitute
Our internal vercmp function was the only user of this, and it no longer
relies on it.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-24 22:16:28 -05:00
Dan McGee 29bf6814f7 Use access() instead of stat() when possible
We were using the stat() system call in quite a few places when we didn't
actually need anything the stat struct returned- we were simply checking for
file existence. access() will be more efficient in those cases.

Before (strace pacman -Ss pacman):
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 33.16    0.005987           0     19016           stat64

After:
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 34.85    0.003863           0     12633         1 access
  7.95    0.000881           0      6391         7 stat64

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-06-15 22:52:27 -05:00
Dan McGee bf2964dc58 Fix compilation warning on x86_64
Glad we have so many developers using this as their native architecture.
int/size_t issue here.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-14 19:38:58 -05:00
Dan McGee b49fc504ac Update makepath to remove PATH_MAX usage
The start of a few commits to remove some PATH_MAX usage from our code. Use
a dynamically allocated string instead.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-10 00:51:04 -05:00
Dan McGee 010279e449 Updates to _alpm_copyfile()
Rework to use a single #define for the buffsize, and in the process clean up
some other code and double the default buffer size.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-04-28 22:24:40 -05:00
Chantry Xavier 701a03dcdb Completely rework delta algorithm
Using the graph structures that Nagy set up for dependency sorting, we now
do a similar process for deltas. Load up all of the deltas into a graph
object on which we can then apply Dijkstra's algorithm, using the new weight
field of graph struct.
We initialize the nodes weight using the base files that we can use in our
filecache (both filename and md5sum must match). The algorithm then picks
the best path among those that can be resolved.

Note that this algorithm has a few advantages over the old one:
1. It is completely file agnostic. These delta chains do not have to consist
   of package files- this could be adopted to do delta-fied DBs.
2. It does not use the local_db anymore, or even care if a package or file
   is currently installed. Instead, it only looks in the filecache for files
   and packages that match delta chain entries.

Original-work-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2008-04-26 11:36:01 -05:00
K. Piche db4258c1fd Some comments for _alpm_unpack.
Signed-off-by: K. Piche <kevin@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-04-14 17:19:32 -05:00
Dan McGee 4c872594da Remove unnecessary header file, move one macro to util.c
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-04-06 20:20:20 -05:00
Dan McGee e4a4cf7ce5 libalpm error cleanup, step 1
Remove unused error codes, begin refactoring some of the others.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-04-06 20:16:57 -05:00
Dan McGee f8c737d3b6 Add an archive_fgets() function
This crude function allows reading from an archive on a line-by-line basis
similar to the familiar fgets() call on a FILE stream. This is the first
step in being able to read DB entries straight from an archive.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-03-27 12:07:26 -05:00
Chantry Xavier d734ebdde2 libalpm: clean up of md5sum functions.
test_delta_md5sum and test_pkg_md5sum were simple wrappers to test_md5sum,
and only used once, so not very useful. I removed them.
Also, test_md5sum and alpm_pkg_checkmd5sum functions were a bit duplicated,
so I refactored them with a new _alpm_test_md5sum function in libalpm/util.c

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2008-02-27 19:02:17 -06:00
Jaroslaw Swierczynski 801a268056 FS#9183 : force correct permissions on tmp/.
[Xav: removed unneeded makepath_internal function, and fixed the permission
value : 1777 -> 01777]
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-01-13 18:42:26 -06:00
Chantry Xavier 8186dc11a9 Ensure correct dir permissions in the database.
Fix for FS#9176.
A previous commit (6e8daa553b) already forced all database files to 644.
Now the directories are also forced to 755.

Additionally, repo-add now sets the umask to 022, just like makepkg does, to
fix the problem at its root.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-01-13 12:51:37 -06:00
Chantry Xavier ab506f77c0 util.c : fix segfault when the cachedir isn't usable.
For example, if the cachedir is a broken symlink or a non writable
directory, pacman fallbacks to /tmp/. Just before doing that, it freed the
handle->cachedirs list twice !
once in _alpm_filecache_setup, and once in alpm_option_set_cachedirs. So the
first one was removed.

Fixes FS#9186.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2008-01-13 12:21:21 -06:00
Dan McGee 1a0aaa20df Don't stat cachedir immediately
By attempting to stat the cachedir when we load the pacman config, pacman
bails out if it is a non-existant directory, even if it will never be
needed. This is unfortunate as it is only used for sync transactions anyway.
Instead, wait until we need it in _alpm_filecache_setup to actually do
anything.

Reported as FS#9096.

Signed-off-by: Dan McGee <dan@archlinux.org>
2008-01-05 17:39:38 -06:00
Dan McGee 9781d0d637 Update GNU GPL boilerplate and copyright dates
Update the GPL boilerplate to direct people to the GNU website for a copy of
the license, as well as bump all of Judd's copyrights to 2007.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-10 22:55:39 -06:00
Chantry Xavier 2ef78355fc _alpm_unpack: return 1 when the file is not found.
If _alpm_unpack has a specific file to extract (not NULL), but doesn't find
it, it'll now return 1, for indicating the failure.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-08 21:54:46 -06:00
Aaron Griffin 6e8daa553b Force mode of all database files to 644
In the case of a packaging error where install or changelog had bad permissions,
pacman respected the original permissions without trying to fix it - this means
that some operations (changelog) artificially required root permissions to run

In addition, minor function housekeeping on _alpm_unpack

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
2007-11-25 14:03:13 -06:00
Dan McGee 2322909703 War on whitespace
Run the kernel's cleanfile script on all of our source files.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-16 20:18:45 -06:00
Dan McGee 3cd684b41d libalpm: simplify sync db lastupdate
Legacy code is hitting the trash here. Remove unnecessary _alpm_time2string
time storage abstraction in favor of just writing the time_t value to the
disk.

The only drawback is that everyone's sync DBs will have to be updated at
least once so that the lastupdate values are stored right. :)

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-16 11:51:26 -06:00
Dan McGee 2898ccb609 libalpm: fix lstat wrapper to actually use newpath
Commit b55abdce7a introduced an lstat wrapper
function that never dereferences paths with a trailing slash, but still
called lstat on path instead of newpath. Oops!

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-11 09:51:09 -06:00
Chantry Xavier 0686fec839 Remove the newline automatically added by alpm_logaction.
This way, _alpm_logaction behaves like _alpm_log, and gives more control.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2007-11-04 18:04:43 -06:00
Dan McGee b55abdce7a libalpm: use an lstat wrapper so we never dereference dir symlinks
Linux lstat follows POSIX standards and dereferences a symlink pointing
to a directory if there is a trailing slash. For purposes of libalpm, we
don't want this so make a lstat wrapper that suppresses this behavior.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-04 18:02:25 -06:00
Dan McGee 46eaa5c542 Fix invalid static scoping of strverscmp
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-10-22 23:36:03 -05:00
Dan McGee d3c8003020 alpm: removed unused strtoupper wrapper, remove installeddate on parse_descfile
installdate should never be present in a package descfile, so get rid of it.
With the last commit, we also don't need the util strtoupper function.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-09-23 12:20:48 -05:00
Dan McGee 5c9eec5570 libalpm: add newlines to all strings passed to log callback
This allows us to remove the hack in the frontend where we added a newline
to everything coming out of the pm_printf functions, and instead let the
developer put newlines where they want them. This should be the last hangover
of that auto-newline stuff.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-23 22:26:55 -04:00
Dan McGee c22e381a8b Post trial install changes, round one
A bunch of changes related to my first "real" install of pacman-git into
/usr/local and trying to use it.

* Shift some uses of free -> FREE in libalpm.
* Move stat and sanity checks of config paths into libalpm from the
  config and argument parsing in pacman.c.
* Fix issue where dbpath still was not defined early enough due to its
  requirement for being used in alpm_db_register. This should be rewritten
  so it doesn't have this dependency, but this will work for now.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-21 21:28:05 -04:00
Dan McGee 17d9122e01 Fix for FS 6404 and functionalize some cachedir handling stuff
In order to best resolve bug 6404, move some cachedir handling stuff out of
sync.c and into util.c and create two new functions: filecache_find and
filecache_setup. sync.c was rewritten to use these, and alpm_fetch_pkgurl
now also uses these routines.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-20 15:23:46 -04:00
Dan McGee 942175feaa Add const qualifier to md5_file and alpm_get_md5sum
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-20 12:58:17 -04:00
Andrew Fyfe 1cb6d80631 Clean up MD5 code.
* Move alpm md5 functions to lib/libalpm/util.c
	* Remove unneeded includes for md5.h
	* Replace md5 implementation with one from http://www.xyssl.org

Dan: clean up XySSL code by removing parts we don't use, and add a note
saying what changed.
Dan: fix alpm_get_md5sum, off by one error on the malloc call and other
small things.

Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-16 13:17:33 -04:00
Dan McGee a65ad4efc1 package.h: implement origin_data union in pmpkg_t struct
We were using a void *data element in pmpkg_t before, which is unsafe by its
nature of being untyped. Reimplement data as origin_data being a union that
can hold either a path to a package file or a pointer to a cache database,
and make the other necesary updates in the code to reflect this. See package.h
for details.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-08-14 10:14:35 -04:00
Dan McGee 20f73d6299 Remove versioncmp.{c,h}, clean up selective #ifdefs
Remove versioncmp.c by moving all functions to locations that make sense.

Move replacement functions (for building without glibc) into util.c where
they belong, and do proper checks for them instead of using __sun__, etc.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-07-12 15:20:43 -04:00
Dan McGee ea1fef69ad Remove gettext calls from all PM_LOG_DEBUG messages
There is no real reason to burden our translators with these messages, as
anyone helping to debug these will probably want them in English.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-07-10 14:24:58 -04:00
Dan McGee 15e1ce2e70 Various small fixes as suggested by some static code checkers
I ran flawfinder and sparse over the pacman source code and found a few
things that were worth fixing (and were quick fixes).

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-07-06 12:11:55 -04:00
Chantry Xavier f55f7f100f libalpm/add.c,util.c : log ARCHIVE_WARN warning to debug output.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2007-07-01 22:31:40 -04:00
Chantry Xavier 1a3b3bc130 libalpm/util.c : stat returns 0 on success
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
2007-06-28 17:14:26 +02:00
Dan McGee 7daa6708d2 Remove lockfile configuration from frontend, make it job of libalpm
I previously introduced some patches to make just about every path in
pacman/libalpm configurable; doing this with the lockfile seemed a bit too
far and we really should just place the lockfile where it belongs- with the
DB that needs locking.

More details in this thread:
http://archlinux.org/pipermail/pacman-dev/2007-June/008499.html

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-06-27 23:34:38 -04:00
Dan McGee 5a3b595837 Fix wrong permissions on pacnew extraction
First reported here:
http://bbs.archlinux.org/viewtopic.php?pid=261861

Newly created files were done with the standard umask, so those that are
extracted seperately and copied to a .pacnew extension will have the wrong
permissions. This should hopefully fix this.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-06-27 20:32:37 -04:00
Dan McGee 0de5c97193 libalpm/util.c: remove unnecessary include
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-06-20 17:54:42 -04:00
Dan McGee a32ca90192 Remove logmask stuff from backend; switch logging callback to new pm_printf
Remove the logmask functionality from the backend as it has been moved to
the frontend, and change the logging callback function to use pm_printf.

In addition, make much better use of va_list- use the args list instead
of a arbitrarily chosen string to print to in the logging functions.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-06-09 12:57:50 -04:00
Dan McGee 7bd2ff6851 Move DB and cache dirs away from there dependence on ROOTDIR
This change allows us to use all autoconf specified paths, most notably
$(localstatedir). It is quite a change and touches a lot of files, as
all references to the DB and cache were done with the ROOTDIR as a prefix.

* add --lock command-line option to pacman to specify the location of the
  lockfile (this can now be specified at configure time by setting the
  $localstatedir path).
* Rip quite a few settings out of configure.ac as they are now picked by
  setting the paths during configure or make.
* Fix bug with /tmp fallback for sync downloads not working correctly
  (related to root location, now the system tmp dir is used).
* Simplified the parameters to some libalpm functions, and added get/set
  for the new lockfile option.
* Renamed several of the DEFS to names without the PM_ prefix.

Signed-off-by: Dan McGee <dan@archlinux.org>
2007-05-31 02:51:28 -04:00
Aaron Griffin ebad199614 Allow $repo expansion in 'Server' config lines
Small change (addition of a 'strreplace' function) which replaces
any $repo tokens found in a server line with the name of the repo
or section being processed.

While this is more simplistic than suggestions on flyspray, it works
and I think it is cleaner.  Merits can be discussed further.

Ref: FS#6389

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
2007-05-18 01:24:59 -05:00