X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fdata%2Fgrits-http.c;h=01bc7053b61504f3c6b8981604ec444263b23871;hb=7a4b9a5dd98bf84808cf49b5639df27337b5e382;hp=3b0c83ebd6c9fa8774db46cd63b009043a87fc92;hpb=016efba1ae80a50c991947fa74723b392dc1cec6;p=grits diff --git a/src/data/grits-http.c b/src/data/grits-http.c index 3b0c83e..01bc705 100644 --- a/src/data/grits-http.c +++ b/src/data/grits-http.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Andy Spencer + * Copyright (C) 2009-2011 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -192,26 +192,28 @@ gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const char *local, /* Close file */ fclose(fp); - if (path != part && SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) { - g_rename(part, path); + if (path != part) { + if (SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) + g_rename(part, path); g_free(part); } /* Finished */ - if (message->status_code == SOUP_STATUS_CANCELLED) { + guint status = message->status_code; + g_object_unref(message); + if (status == SOUP_STATUS_CANCELLED) { return NULL; - } else if (message->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) { + } else if (status == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) { /* Range unsatisfiable, file already complete */ - } else if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) { + } else if (!SOUP_STATUS_IS_SUCCESSFUL(status)) { g_warning("GritsHttp: done_cb - error copying file, status=%d\n" "\tsrc=%s\n" "\tdst=%s", - message->status_code, uri, path); + status, uri, path); return NULL; } } - /* TODO: free everything.. */ return path; } @@ -247,11 +249,12 @@ GList *grits_http_available(GritsHttp *http, const gchar *file; gchar *path = _get_cache_path(http, cache); GDir *dir = g_dir_open(path, 0, NULL); - while ((file = g_dir_read_name(dir))) + while (dir && (file = g_dir_read_name(dir))) if (g_regex_match(filter_re, file, 0, NULL)) files = g_list_prepend(files, g_strdup(file)); g_free(path); - g_dir_close(dir); + if (dir) + g_dir_close(dir); } /* Add online files if online */