Do not re-download firmware that exists in the cache

This commit is contained in:
Richard Hughes 2017-06-05 09:23:10 +01:00
parent 01c13d1634
commit 502a2ca64a

View File

@ -581,6 +581,22 @@ fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error)
return fwupd_client_verify_update (priv->client, values[0], NULL, error);
}
static gboolean
fu_util_file_exists_with_checksum (const gchar *fn,
const gchar *checksum_expected,
GChecksumType checksum_type)
{
gsize len = 0;
g_autofree gchar *checksum_actual = NULL;
g_autofree gchar *data = NULL;
if (!g_file_get_contents (fn, &data, &len, NULL))
return FALSE;
checksum_actual = g_compute_checksum_for_data (checksum_type,
(guchar *) data, len);
return g_strcmp0 (checksum_expected, checksum_actual) == 0;
}
static gboolean
fu_util_download_file (FuUtilPrivate *priv,
SoupURI *uri,
@ -598,6 +614,12 @@ fu_util_download_file (FuUtilPrivate *priv,
g_autoptr(SoupMessage) msg = NULL;
g_autoptr(SoupSession) session = NULL;
/* check if the file already exists with the right checksum */
if (fu_util_file_exists_with_checksum (fn, checksum_expected, checksum_type)) {
g_debug ("skpping download as file already exists");
return TRUE;
}
/* create the soup session */
user_agent = g_strdup_printf ("%s/%s", PACKAGE_NAME, PACKAGE_VERSION);
session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, user_agent,