From 400942fedf35d4fc6b584b8f1552f1ec649136fe Mon Sep 17 00:00:00 2001
From: Dave Reisner <dreisner@archlinux.org>
Date: Sun, 4 Sep 2011 14:59:17 -0400
Subject: avoid blowing out the filecache list when using tmpdir
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

_alpm_filecache_setup() destroys the list of cachedirs when it finds no
writeable directories in the config. This put us in an awkward situation
where _alpm_filecache_find() would locate a downloaded file in a r/o
cachedir, but then fail to install it after _alpm_filecache_setup() is
called (with a NULL argument). Change this behavior to merely prepend
the temporary directory to the list of available cachedirs.

Dan exposed it in e07547ee4ed4, as now a package can be found in a
directory we may not be able to actually store packages in.

Reported-by: Rémy Oudompheng <remy@archlinux.org>
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
 lib/libalpm/util.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 44dead83..58274ed1 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -699,10 +699,8 @@ const char *_alpm_filecache_setup(alpm_handle_t *handle)
 	} else {
 		tmpdir = "/tmp";
 	}
-	i = alpm_list_add(NULL, tmpdir);
-	alpm_option_set_cachedirs(handle, i);
-	alpm_list_free(i);
-	cachedir = handle->cachedirs->data;
+	alpm_option_add_cachedir(handle, tmpdir);
+	cachedir = handle->cachedirs->prev->data;
 	_alpm_log(handle, ALPM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
 	_alpm_log(handle, ALPM_LOG_WARNING,
 			_("couldn't find or create package cache, using %s instead\n"), cachedir);
-- 
cgit v1.2.3-70-g09d2