From 695656d25279342f80c307035721ced6d37ee08b Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Tue, 16 Nov 2010 16:24:52 +1000 Subject: Add function to match file to mount point For a given file, determine which mount point it is on or will be installed to. Take into account that we might be using an alternative installation root. Add additional helper function added to sort mount point list for easier matching. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- lib/libalpm/diskspace.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/libalpm/diskspace.c') diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index a5beb84f..9d153fb4 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -38,6 +38,12 @@ #include "alpm_list.h" #include "util.h" #include "log.h" +#include "handle.h" + +static int mount_point_cmp(const alpm_mountpoint_t *mp1, const alpm_mountpoint_t *mp2) +{ + return(strcmp(mp1->mount_dir, mp2->mount_dir)); +} static alpm_list_t *mount_point_list() { @@ -121,9 +127,31 @@ static alpm_list_t *mount_point_list() } #endif + mount_points = alpm_list_msort(mount_points, alpm_list_count(mount_points), + (alpm_list_fn_cmp)mount_point_cmp); return(mount_points); } +static alpm_list_t *match_mount_point(const alpm_list_t *mount_points, const char *file) +{ + char real_path[PATH_MAX]; + snprintf(real_path, PATH_MAX, "%s%s", handle->root, file); + + alpm_list_t *mp = alpm_list_last(mount_points); + do { + alpm_mountpoint_t *data = mp->data; + + if(strncmp(data->mount_dir, real_path, strlen(data->mount_dir)) == 0) { + return mp; + } + + mp = mp->prev; + } while (mp != alpm_list_last(mount_points)); + + /* should not get here... */ + return NULL; +} + int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db) { alpm_list_t *mount_points; -- cgit v1.2.3-24-g4f1b