X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fdata.c;h=fa11ea8460f03cdfb1738c89e4ccac416c182e81;hb=47c93b9c86bcb79df6f28a3c253be9b9644a1c34;hp=c36556d7644bd453810a732ffa11982a42bea82f;hpb=8efa2df296f672505211b4360c10279d9d57be22;p=grits diff --git a/src/data.c b/src/data.c index c36556d..fa11ea8 100644 --- a/src/data.c +++ b/src/data.c @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2009 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include @@ -27,6 +44,15 @@ static void cache_file_cb(GObject *source_object, GAsyncResult *res, gpointer _i g_free(info); } +static goffset g_file_get_size(GFile *file) +{ + GError *error = NULL; + GFileInfo *info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, &error); + if (error) + g_warning("unable to get file size: %s", error->message); + return g_file_info_get_size(info); +} + /** * Cache a image from Ridge to the local disk * \param path Path to the Ridge file, starting after /ridge/ @@ -36,25 +62,30 @@ void cache_file(char *base, char *path, AWeatherCacheDoneCallback callback, gpoi { gchar *url = g_strconcat(base, path, NULL); gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL); - if (g_file_test(local, G_FILE_TEST_EXISTS)) { - callback(local, user_data); - } else { - if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) - g_mkdir_with_parents(g_path_get_dirname(local), 0755); - cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t)); - info->callback = callback; - info->src = url; - info->dst = local; - info->user_data = user_data; - GFile *src = g_file_new_for_uri(url); - GFile *dst = g_file_new_for_path(local); - g_file_copy_async(src, dst, - G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags, - 0, // int io_priority, - NULL, // GCancellable *cancellable, - NULL, // GFileProgressCallback progress_callback, - NULL, // gpointer progress_callback_data, - cache_file_cb, // GAsyncReadyCallback callback, - info); // gpointer user_data - } + GFile *src = g_file_new_for_uri(url); + GFile *dst = g_file_new_for_path(local); + + if (!g_file_test(local, G_FILE_TEST_EXISTS)) + g_message("Caching file: local does not exist - %s", local); + else if (g_file_get_size(src) != g_file_get_size(dst)) + g_message("Caching file: sizes mismatch - %lld != %lld", + g_file_get_size(src), g_file_get_size(dst)); + else + return callback(local, user_data); + + if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) + g_mkdir_with_parents(g_path_get_dirname(local), 0755); + cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t)); + info->callback = callback; + info->src = url; + info->dst = local; + info->user_data = user_data; + g_file_copy_async(src, dst, + G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags, + 0, // int io_priority, + NULL, // GCancellable *cancellable, + NULL, // GFileProgressCallback progress_callback, + NULL, // gpointer progress_callback_data, + cache_file_cb, // GAsyncReadyCallback callback, + info); // gpointer user_data }