void kuid_atom_free(const kuid_t *k) { atom_sha1_free((const struct sha1 *) k); }
/** * Locate statistics structure for the file. * * If a SHA1 is given, we search by SHA1. Otherwise we search by (name, size) * and if the record is missing the SHA1, probably because it was not * available at the time of insertion, then it is added to the structure * and recorded as such. */ static struct ul_stats * upload_stats_find(const struct sha1 *sha1, const char *pathname, guint64 size) { struct ul_stats *s = NULL; if (upload_stats_list) { static const struct ul_stats zero_stats; struct ul_stats key; gconstpointer orig_key; g_assert(upload_stats_by_sha1); if (sha1) { s = g_hash_table_lookup(upload_stats_by_sha1, sha1); if (s) goto done; /* Found it by SHA1 */ } key = zero_stats; key.pathname = atom_str_get(pathname); key.size = size; if (hash_list_find(upload_stats_list, &key, &orig_key)) s = deconstify_gpointer(orig_key); atom_str_free_null(&key.pathname); if (s && sha1) { /* Was missing from the by-SHA1 table */ if (NULL == s->sha1) { /* SHA1 was unknown */ s->sha1 = atom_sha1_get(sha1); } else { /* SHA1 changed, file was modified */ struct ul_stats *old = g_hash_table_lookup(upload_stats_by_sha1, s->sha1); g_assert(old == s); /* Must be the same filename entry */ g_hash_table_remove(upload_stats_by_sha1, s->sha1); atom_sha1_free(s->sha1); s->sha1 = atom_sha1_get(sha1); } gm_hash_table_insert_const(upload_stats_by_sha1, s->sha1, s); } } done: /* We guarantee the SHA1 is present in the record if known */ g_assert(!(s && sha1) || s->sha1); /* Postcondition: if we return something, it must be "correct" */ if (s != NULL) { g_assert(atom_is_str(s->pathname)); g_assert(atom_is_str(s->filename)); g_assert(s->norm >= 0.0); } return s; }