summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-11-04 18:02:25 -0600
committerDan McGee <dan@archlinux.org>2007-11-04 18:02:25 -0600
commitb55abdce7aebb142ce79da3aa3645afe7693a3c4 (patch)
treea19e1595cb92d4a3571a88acd76ad564fea0aead /lib/libalpm/util.c
parent99f42d6bd2116b0bd8f75394fe92255ca1f4c80b (diff)
downloadpacman-b55abdce7aebb142ce79da3aa3645afe7693a3c4.tar.xz
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>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 016c0f40..5df3a025 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -432,7 +432,7 @@ int _alpm_rmrf(const char *path)
char name[PATH_MAX];
struct stat st;
- if(lstat(path, &st) == 0) {
+ if(_alpm_lstat(path, &st) == 0) {
if(!S_ISDIR(st.st_mode)) {
if(!unlink(path)) {
return(0);
@@ -597,6 +597,30 @@ const char *_alpm_filecache_setup(void)
return(alpm_list_getdata(tmp));
}
+/** lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink.
+ * Linux lstat follows POSIX semantics and still performs a dereference on
+ * the first, and for uses of lstat in libalpm this is not what we want.
+ * @param path path to file to lstat
+ * @param buf structure to fill with stat information
+ * @return the return code from lstat
+ */
+int _alpm_lstat(const char *path, struct stat *buf)
+{
+ int ret;
+ char *newpath = strdup(path);
+ int len = strlen(newpath);
+
+ /* strip the trailing slash if one exists */
+ if(len != 0 && newpath[len - 1] == '/') {
+ newpath[len - 1] = '\0';
+ }
+
+ ret = lstat(path, buf);
+
+ FREE(newpath);
+ return(ret);
+}
+
/** Get the md5 sum of file.
* @param filename name of the file
* @return the checksum on success, NULL on error