diff options
author | Dan McGee <dan@archlinux.org> | 2010-12-12 22:41:02 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-12-12 22:41:02 -0600 |
commit | 1ff8118212cf566607c61e2f340dc3064c67c2ac (patch) | |
tree | 7c3352044b308f0c169aa550c26c8d55a86124fa /lib | |
parent | 13a2847aa14cb7643d50ca82b00180b440e401fe (diff) | |
download | pacman-1ff8118212cf566607c61e2f340dc3064c67c2ac.tar.xz |
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 <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/be_sync.c | 18 |
1 files changed, 18 insertions, 0 deletions
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); |