From 1ff8118212cf566607c61e2f340dc3064c67c2ac Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 12 Dec 2010 22:41:02 -0600 Subject: Create sync/ DB directory if it does not exist Rather than error out, this is easy enough. Looks quite similar to the code in be_local for creating the local directory. Signed-off-by: Dan McGee --- lib/libalpm/be_sync.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/libalpm') diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index f708b16d..8d770005 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -81,6 +81,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) { char *dbfile, *syncpath; const char *dbpath; + struct stat buf; size_t len; int ret; @@ -103,6 +104,23 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1)); sprintf(syncpath, "%s%s", dbpath, "sync/"); + if(stat(syncpath, &buf) != 0) { + _alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n", + syncpath); + if(_alpm_makepath(syncpath) != 0) { + free(dbfile); + free(syncpath); + RET_ERR(PM_ERR_SYSTEM, -1); + } + } else if(!S_ISDIR(buf.st_mode)) { + _alpm_log(PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath); + if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) { + free(dbfile); + free(syncpath); + RET_ERR(PM_ERR_SYSTEM, -1); + } + } + ret = _alpm_download_single_file(dbfile, db->servers, syncpath, force); free(dbfile); free(syncpath); -- cgit v1.2.3-24-g4f1b