summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
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